t27.aiРусский

A test block

You will learn

How a test block is written and what a failing assert reports.

A test block starts with the keyword test and a name, and holds assert lines in braces. Each assert takes an expression that must be true. When one is false, the report names the test and the number of the assert, for example assert #1 is false. A spec's tests are its claims about itself, which is why every course spec on this site carries some.

Try it

Break the test on purpose by changing DAYS, then read the failure line.

Open the interactive lesson →

t27 basics 10: a test block, passing and failing
t27 basics 10: a test block, passing and failing ↗

A t27 test block and the report it gives when it passes and when an assert is false. Lesson 10 of the t27 basics course.

specs/basics/10_a_test_block.t27

// SPDX-License-Identifier: Apache-2.0
; t27 basics, lesson 10: A test block.
; A test is a name and a list of asserts; each assert must be true.

module basics_10_a_test_block;

pub const DAYS : u16 = 365;
pub const WEEKS : u16 = 52;

test a_year_is_52_weeks_and_a_day {
    assert WEEKS * 7 + 1 == DAYS;
}

Open the lesson's spec in the player ↗

All lessons