# Running the Exercise Tests

What an exercise's tests are, how to run them in your language with one command, and how to read a red run and a green one, including the "Not yet" message that says what to fix.

Novice · Data Structures · Software Development · Updated November 17, 2026

By Gregor Dzierzon

## After this lesson you can

- Run an exercise's tests in your language and tell a passing run from a failing one
- Read a failing test's message to find out what your code should do

## Key takeaways

- A test is a small program that runs your code with known inputs and checks the answers, like a checklist the computer ticks off.
- Every exercise starts red, on purpose. Each function you finish turns its tests green.
- Each language has one command that runs the tests, from the exercise's folder for that language.
- A failing test's message starts with "Not yet:" and says what it expected, so read it before you change anything.

Every chapter of this course ends with an exercise: a small program for you to finish, with **tests** that tell you when it works. You never have to guess whether you're done, and you never wait for someone to mark it. This lesson shows what a test is, how to run them in your language, and how to read what they say.

## A test is a checklist the computer ticks off

Think of a restaurant's opening checklist: *the fryer is on, the register has $100 in it, the doors are unlocked*. Someone walks through it and ticks each line, or writes down what's wrong. A **test** is the same thing for code: a small program that runs your code with inputs it knows the answers for, and checks each answer.

Here's one real test from the first exercise, *The Lost and Found*. It hands eight items to the lost-and-found desk, then checks that tag 0 is the first item handed in and tag 6 the seventh. A line that does the checking is called an **assertion**: it asserts, or claims, that two values are equal, with a message to show if they're not.

```csharp
[TestMethod]
public void ItemWithTagGivesTheItemsInTheOrderTheyCameIn()
{
    Desk desk = SmallDesk();
    Assert.AreEqual("Red Umbrella", desk.ItemWithTag(0), "Not yet: tag 0 is the first item handed in, the Red Umbrella.");
    Assert.AreEqual("Blue Water Bottle", desk.ItemWithTag(6), "Not yet: tag 6 is the seventh item handed in, the Blue Water Bottle.");
}
```

```java
@Test
void itemWithTagGivesTheItemsInTheOrderTheyCameIn() {
    Desk desk = smallDesk();
    assertEquals("Red Umbrella", desk.itemWithTag(0), "Not yet: tag 0 is the first item handed in, the Red Umbrella.");
    assertEquals("Blue Water Bottle", desk.itemWithTag(6), "Not yet: tag 6 is the seventh item handed in, the Blue Water Bottle.");
}
```

```python
def test_item_with_tag_gives_the_items_in_the_order_they_came_in():
    desk = small_desk()
    assert desk.item_with_tag(0) == "Red Umbrella", "Not yet: tag 0 is the first item handed in, the Red Umbrella."
    assert desk.item_with_tag(6) == "Blue Water Bottle", "Not yet: tag 6 is the seventh item handed in, the Blue Water Bottle."
```

```javascript
test("item with tag: gives the items in the order they came in", () => {
  const desk = smallDesk();
  assert.equal(desk.itemWithTag(0), "Red Umbrella", "Not yet: tag 0 is the first item handed in, the Red Umbrella.");
  assert.equal(desk.itemWithTag(6), "Blue Water Bottle", "Not yet: tag 6 is the seventh item handed in, the Blue Water Bottle.");
});
```

```typescript
test("item with tag: gives the items in the order they came in", () => {
  const desk = smallDesk();
  assert.equal(desk.itemWithTag(0), "Red Umbrella", "Not yet: tag 0 is the first item handed in, the Red Umbrella.");
  assert.equal(desk.itemWithTag(6), "Blue Water Bottle", "Not yet: tag 6 is the seventh item handed in, the Blue Water Bottle.");
});
```

You read tests; you don't write them. Each exercise comes with its tests written, and you never need to change them. Your job is to make them pass.

## Tests that check one small piece are unit tests

Each test checks one small piece, one function with one kind of input, so when it fails you know exactly where to look. Tests like these are called **unit tests**. The program that finds every test in a folder, runs them all and prints the score is the **test runner**. Each language has its own, and each exercise is set up for it:

| Language | Test runner | Run the tests with |
|---|---|---|
| C# | MSTest | `dotnet test` |
| Java | JUnit, run by Maven | `./mvnw test` (`.\mvnw test` in PowerShell) |
| Python | pytest | `python -m pytest` |
| JavaScript | Node's built-in runner | `npm test` |
| TypeScript | Node's built-in runner, after the TypeScript check | `npm test` |

Run the command in VS Code's terminal, in **your language's folder** of the exercise (open that folder with **File > Open Folder**). Python needs a virtual environment with pytest in it first, and TypeScript needs `npm install` once; each exercise's README walks you through both.

## Red first, on purpose

When you first download an exercise, **its tests fail**. That's how it's meant to be: the code you start from returns placeholder answers (`0`, or nothing), or it's today's slow version that the exercise asks you to fix, so some or all of the tests don't check out yet. Developers call a run with any failing test **red** and a run where every test passes **green**, after the colors many test runners use.

Here's how the end of a run looks in each language for *The Lost and Found*, which has 7 tests: first as you download it (today's desk already passes 3 of them), then with the work done.

| Language | Red: as you download it | Green: every function finished |
|---|---|---|
| C# | `Failed!  - Failed: 4, Passed: 3, Skipped: 0, Total: 7` | `Passed!  - Failed: 0, Passed: 7, Skipped: 0, Total: 7` |
| Java | `Tests run: 7, Failures: 4, Errors: 0, Skipped: 0`, then `BUILD FAILURE` | `Tests run: 7, Failures: 0, Errors: 0, Skipped: 0`, then `BUILD SUCCESS` |
| Python | `4 failed, 3 passed` | `7 passed` |
| JavaScript and TypeScript | `ℹ pass 3` and `ℹ fail 4` | `ℹ pass 7` and `ℹ fail 0` |

![VS Code's terminal after running python -m pytest twice: the first run, on the starter, ends in red with 4 failed, 3 passed and a Not yet message for each failing test; the second, after the work is done, ends in green with 7 passed](https://www.ask-codey.com/lessons/TODO)

You don't have to finish everything to see progress. Finish one method, run the tests again, and its tests turn green while the others stay red. Small steps, run often.

## Read the "Not yet" message

When a test fails, its message says what it expected. Every message in this course starts with **Not yet:**, because a failing test isn't a mistake, just a thing you haven't done yet:

```text
Not yet: finding Water Bottle 16 took 121 looks. The lunch line needs 120 or fewer, even with 800 items.
```

Read that before you change anything. It tells you which job, which input and what went wrong. Then look at your code with that one example in mind: why did finding one item take 121 looks?

The runner also prints a lot of other lines (file paths, line numbers, the expected and actual values). You don't need all of it. Find the **Not yet** line, and the line just above or below it that names the test.

**Try it.** If you've set up your language, download *The Lost and Found* from its lesson at the end of this chapter, open your language's folder, and run the tests now, before you write anything. You should see 4 tests red, each with its Not yet message, and 3 already green.

## Check yourself

2 questions to try on the lesson page.

## So what

Every exercise in the course works this way: one command, red at first, green when you're done. You can check your own work any time, as often as you like, without waiting for anyone.

## Key terms

- [Unit Test](https://www.ask-codey.com/glossary/unit-test-unit-testing)
- [Test Runner](https://www.ask-codey.com/glossary/test-runner)
- [Assertion](https://www.ask-codey.com/glossary/assertion-unit-testing)

## Cheat sheets

- [Running the Exercise Tests](https://www.ask-codey.com/cheat-sheets/ds-running-the-tests-cheat-sheet)

Source: https://www.ask-codey.com/lessons/ds-running-the-tests
