Mojo struct
TestSuite
struct TestSuite
A suite of tests to run.
You can automatically collect and register test functions starting with
test_
by calling the discover_tests
static method, and then running the
entire suite by calling the run
method.
Example:
from testing import assert_equal, TestSuite
def test_something():
assert_equal(1 + 1, 2)
def test_some_other_thing():
assert_equal(2 + 2, 4)
def main():
TestSuite.discover_tests[__functions_in_module()]().run()
Alternatively, you can manually register tests by calling the test
method.
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]
): - location (
_SourceLocation
):
Implemented traits
AnyType
,
Movable
,
UnknownDestructibility
Aliases
__del__is_trivial
alias __del__is_trivial = False
__moveinit__is_trivial
alias __moveinit__is_trivial = True
Methods
__init__
__init__(out self, *, location: Optional[_SourceLocation] = None)
Create a new test suite.
Arguments:
location: The location of the test suite (defaults to
__call_location
).
__del__
__del__(var self)
discover_tests
static discover_tests[test_funcs: Tuple[element_types], /](*, location: Optional[_SourceLocation] = None) -> Self
Discover tests from the given list of functions, and register them.
Arguments:
location: The location of the test suite (defaults to
__call_location
).
Parameters:
- test_funcs (
Tuple
): The pack of functions to discover tests from. In most cases, callers should pass__functions_in_module()
.
test
test[f: fn() raises -> None](mut self)
Registers a test to be run.
Parameters:
- f (
fn() raises -> None
): The function to run.
generate_report
generate_report(mut self) -> TestSuiteReport
Runs the test suite and generates a report.
Returns:
TestSuiteReport
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.
disable
disable(var self)
Disables the test suite, not running any of the tests.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!