Composable assertions
This module contains functions for building and combining Matcher
s that
can be used to build up assertions for testing.
import M "mo:matchers/Matchers";
import T "mo:matchers/Testable";
assertThat(5 + 5, M.equals(T.nat(10)));
assertThat(5 + 5, M.allOf<Nat>([M.greaterThan(8), M.lessThan(12)]));
assertThat([1, 2], M.array([M.equals(T.nat(1)), M.equals(T.nat(2))]));
A simple test runner
The functions in this module let you build up trees of tests, and run them.
import M "mo:matchers/Matchers";
import T "mo:matchers/Testable";
import Suite "mo:matchers/Suite";
let suite = Suite.suite("My test suite", [
Suite.suite("Nat tests", [
Suite.test("10 is 10", 10, M.equals(T.nat(10))),
Suite.test("5 is greater than three", 5, M.greaterThan<Nat>(3)),
])
]);
Suite.run(suite);
Things we can compare in tests
This module contains the Testable<A>
abstraction, which bundles
toText
and equals
for a type A
so we can use them as "expected"
values in tests.
It also contains a few helpers to build Testable
's for compound types
like Arrays and Optionals. If you want to test your own objects or control
how things are printed and compared in your own tests you'll need to create
your own Testable
's.
import T "mo:matchers/Testable";
type Person = { name : Text, surname : ?Text };
// Helper
let optText : Testable<(?Text)> = T.optionalTestable(T.textTestable)
let testablePerson : Testable<Person> = {
display = func (person : Person) : Text =
person.name # " " #
optText.display(person.surname)
equals = func (person1 : Person, person2 : Person) : Bool =
person1.name == person2.name and
optText.equals(person1.surname, person2.surname)
}
Matchers for Hashmaps
This module contains utility matchers that make it easier to write assertions that involve Hashmaps.
Unit testing for canisters
The
Tester
class in this module can be used to define unit tests for canisters.