---
title: "1.7 Testing it"
url: https://una-lang.org/en/learn/hello/testing-it/
release: v0.4.0
edition: "0.2"
---

# 1.7 Testing it

## 1.7.1 What an example is

An **example** is a check that lives next to the code: it calls a function and says what the call must give back. `una test .` runs every example of the package and reports each one. The morning notices have one example per notice:

```una include="day-to-day/src/morning.una#L57-L63" title="day-to-day/src/morning.una" caption="the first two examples"
example "the notices start with the store's name"
  do store_name()
  expect result == "Harbor Street store"

example "the address gives the street"
  do store_address()
  expect result == "12 Harbor Street, by the ferry"
```

Each example has three lines:

1. **`example "…"`.** The keyword `example` and a sentence that says what the example shows. It names the example in the report.
2. **`do greeting()`.** The call to make, indented two spaces.
3. **`expect result == "Good morning"`.** What must hold afterwards: `result` stands for what the call gave back, and `==` means "is equal to".

This is the simplest form of an example. [Chapter 14](https://una-lang.org/en/learn/testing/examples-do-and-expect/#s14-1) covers examples in full.

## 1.7.2 One example per notice

Every function that gives back a text has an example that states the exact text. An example of the whole text catches a change of one character, such as a missing space, which is easy to miss when you read the output.

## 1.7.3 Running the examples

In the `day-to-day` directory, `una test .` checks the package first, then runs the examples:

```text include="day-to-day/expected/commands/test.txt#L2-L11"
example morning "the notices start with the store's name" ... ok
example morning "the address gives the street" ... ok
example morning "the greeting is for the morning" ... ok
example morning "the hours give the opening and the closing time" ... ok
example morning "the cutoff names the hour" ... ok
example morning "the offer names what is on sale" ... ok
example morning "the café keeps its own hours" ... ok
example morning "the help desk says where to go" ... ok

8 examples: 8 passed, 0 failed
```

Each example takes one line of the report. When an example fails, its line says `FAILED`, with the line of the `expect` and the value `result` had; the exercises of [Exercises](https://una-lang.org/en/learn/hello/exercises/#s1-9) start from such a report.

## 1.7.4 What the examples leave out: the printing functions

The examples do not call `main`, `section` or `rule`. These functions print, and an example of a function that prints needs a stand-in for the console, which [chapter 14](https://una-lang.org/en/learn/testing/fakes-given-expect-performed-and-expect-not-performed/#s14-3) shows. The printing functions here only print what the tested functions give back, so the examples cover what can go wrong: the text of each notice.
