Version: 1.1.0

Testing

Mojo tests are functions that call helpers from the testing module. A failure is a raised error, so the test runner reports the file.

Essentials

  • Keep tests next to the code or in a dedicated test file.
  • Name the file so mojo test can find it.
  • Compare values with the assertion helpers rather than a bare if.
  • Tests should be deterministic. Seed any random input.

Example

from testing import assert_equal

def test_add():
    assert_equal(1 + 1, 2)

Keep in mind

One behavior per test makes a failure obvious. A test that checks twelve things hides the first regression.