Skip to content

Commit fd0dc95

Browse files
committed
[docs] Improve mops test documentation with replica and verbose options
1 parent 03aecad commit fd0dc95

File tree

1 file changed

+45
-18
lines changed

1 file changed

+45
-18
lines changed

docs/docs/cli/4-dev/01-mops-test.md

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,27 @@ You can also specify `wasi` mode for a specific test file by adding the line bel
6767
// @testmode wasi
6868
```
6969

70-
**Replica tests**
70+
### `--replica`
71+
72+
Which replica to use to run actor tests.
73+
74+
Default `pocket-ic` if `pocket-ic` is specified in `mops.toml` in `[toolchain]` section, otherwise `dfx`.
75+
76+
Possible values:
77+
- `dfx` - use `dfx` local replica
78+
- `pocket-ic` - use [PocketIC](https://pypi.org/project/pocket-ic/) light replica via [pic.js](https://www.npmjs.com/package/@hadronous/pic) wrapper
79+
80+
:::info
81+
If you run `mops test --replica pocket-ic` AND `pocket-ic` is not specified in `mops.toml` in `[toolchain]` section, Mops will use pocket-ic replica that comes with dfx (`dfx start --pocketic`).
82+
:::
83+
84+
### `--verbose`
85+
86+
Show replica logs
87+
88+
89+
90+
## Replica tests
7191

7292
Replica tests are useful if you need to test actor code which relies on the IC API(cycles, timers, canister upgrades, etc.).
7393

@@ -82,27 +102,34 @@ actor {
82102
};
83103
```
84104

85-
See example [here](https://github.com/ZenVoich/mops/blob/main/test/storage-actor.test.mo).
86-
87-
Under the hood, Mops will:
88-
- Start a local replica on port `4945`
89-
- Compile test files and deploy them
90-
- Call `runTests` method of the deployed canister
105+
Example:
106+
```motoko
107+
import {test} "mo:test/async";
108+
import MyCanister "../my-canister";
91109
92-
### `--replica`
110+
actor {
111+
// add cycles to deploy your canister
112+
ExperimentalCycles.add<system>(1_000_000_000_000);
93113
94-
Which replica to use to run actor tests.
114+
// deploy your canister
115+
let myCanister = await MyCanister.MyCanister();
95116
96-
Default `pocket-ic` if `pocket-ic` is specified in `mops.toml` in `[toolchain]` section, otherwise `dfx`.
117+
public func runTests() : async () {
118+
await test("test name", func() : async () {
119+
let res = await myCanister.myFunc();
120+
assert res == 123;
121+
});
122+
};
123+
};
124+
```
97125

98-
Possible values:
99-
- `dfx` - use `dfx` local replica
100-
- `pocket-ic` - use [PocketIC](https://pypi.org/project/pocket-ic/) light replica via [pic.js](https://www.npmjs.com/package/@hadronous/pic) wrapper
126+
Make sure your actor doesn't have a name `actor {`.
101127

102-
:::info
103-
If you run `mops test --replica pocket-ic` AND `pocket-ic` is not specified in `mops.toml` in `[toolchain]` section, Mops will use pocket-ic replica that comes with dfx (`dfx start --pocketic`).
104-
:::
128+
Make sure your actor has `runTests` method.
105129

106-
### `--verbose`
130+
See example [here](https://github.com/ZenVoich/mops/blob/main/test/storage-actor.test.mo).
107131

108-
Show replica logs
132+
Under the hood, Mops will:
133+
- Start a local replica on port `4945`
134+
- Compile test files and deploy them
135+
- Call `runTests` method of the deployed canister

0 commit comments

Comments
 (0)