t27.aiРусский

Many tests in one spec

You will learn

Why several small tests read better than one long one, and how the report counts them.

A spec may hold any number of test blocks. Each one checks one idea and has a name that says which. The report counts tests and asserts separately: the lesson spec has 3 tests and 5 asserts. When one fails, its name tells you which idea broke, and the other tests still report on their own ideas.

Try it

Make one of the three tests fail and check that the other two still pass.

Open the interactive lesson →

t27 basics 11: three tests, one idea each
t27 basics 11: three tests, one idea each ↗

The tests of a t27 spec counted one by one, with the asserts in each, from the lesson spec. Lesson 11 of the t27 basics course.

specs/basics/11_many_tests.t27

// SPDX-License-Identifier: Apache-2.0
; t27 basics, lesson 11: Many tests in one spec.
; Split checks into small named tests, so a failure points at one idea.

module basics_11_many_tests;

pub const HOURS : u8 = 24;
pub const MINUTES : u8 = 60;
pub const DAYS_IN_WEEK : u8 = 7;

test a_day_has_24_hours {
    assert HOURS == 24;
}

test an_hour_has_60_minutes {
    assert MINUTES == 60;
    assert MINUTES > HOURS;
}

test a_week_has_7_days {
    assert DAYS_IN_WEEK == 7;
    assert DAYS_IN_WEEK < HOURS;
}

Open the lesson's spec in the player ↗

All lessons