mops test
Mops can run Motoko unit tests
mops test
Put your tests in test/*.test.mo
files.
All tests run as quickly as possible thanks to parallel execution.
See test package to help you write tests.
Options
--reporter
, -r
Test reporter.
--reporter <reporter>
Available reporters:
verbose
- print each test namefiles
- print only test filescompact
- pretty progress barsilent
- print only errors
Default verbose
if there is only one file to test and files
otherwise.
--watch
, -w
Re-run tests every time you change *.mo files.
--watch
--mode
Test run mode
--mode <mode>
Available modes:
interpreter
- run tests viamoc -r
(default)wasi
- compile test file to wasm and execute it withwasmtime
. Useful, when you useto_candid
/from_candid
, or if you get stackoverflow errors.
You can also specify wasi
mode for a specific test file by adding the line below as the first line in the test file
// @testmode wasi
Replica tests
Replica tests are useful if you need to test actor code which relies on the IC API(cycles, timers, canister upgrades, etc.).
To run replica tests, your test file should look like this:
...
actor {
public func runTests() : async () {
// your tests here
};
};
See example here.
Under the hood, Mops will:
- Start a local replica on port
4945
- Compile test files and deploy them
- Call
runTests
method of the deployed canister
--replica
Which replica to use to run actor tests.
Default pocket-ic
if pocket-ic
is specified in mops.toml
in [toolchain]
section, otherwise dfx
.
Possible values: