Motoko unit testing with Mops

That is how motoko interpreter handles Time.now(), you can rewrite tests to replica test mode and use pocket-ic replica for faster runs.

image

Does pocket-ic allow fine-grained control of the time?

I usually write classes that take a now() : Nat function as a constructor argument (or some similar approach). That way we can inject a function that I control for tests, and test conveniently with the interpreter. And we can inject Time.now() for the real deployment.

I used to do this as well but pocket ic lets you set the exact time of each execution if you want that level of control.

This file has some examples where we test the subscription service: icrc79.mo/pic/subs/subs.test.ts at main · PanIndustrial-Org/icrc79.mo · GitHub