Skip to main content

Mojo struct

TestSuite

struct TestSuite

A suite of tests to run.

You can enqueue tests by calling the test method, and then running the entire suite by calling the run method.

Example:

from testing import assert_equal, TestSuite

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

def main():
    var suite = TestSuite()

    suite.test[some_test]()

    suite^.run()

Fields

  • tests (List[_Test]):
  • name (StringSlice[StaticConstantOrigin]):

Implemented traits

AnyType, Movable, UnknownDestructibility

Aliases

__del__is_trivial

alias __del__is_trivial = False

__moveinit__is_trivial

alias __moveinit__is_trivial = StringSlice[StaticConstantOrigin].__moveinit__is_trivial if List[_Test].__moveinit__is_trivial else List[_Test].__moveinit__is_trivial

Methods

__init__

__init__(out self)

Create a new test suite.

__del__

__del__(var self)

test

test[f: fn() raises -> None](mut self)

Enqueues a test to run.

Parameters:

  • f (fn() raises -> None): The function to run.

run

run(var self)

Runs the test suite and prints the results to the console.

Raises:

An error if a test in the test suite fails.

Was this page helpful?