Hello. I was wondering if there is an easy way for testing async functions. When I tried to do it I realized I needed to install an async reactor like tokio. But I had issues with some dependencies and the compilation to wasm (I don’t recall exactly, but I think some parts of tokio needed for testing couldn’t be compiled to wasm). A lot of the code I use is async, so most of my functions are not tested.
Is there a standard way to test async functions (in Rust, for ICP)?
If you write your canister without async (which is doable if you don’t make calls to other canisters) then you can separate the canister interface from the canister logic and stick with unit tests. Example: canister logic, canister interface, tests.
If your canister uses async but you still can separate interface and logic then you can do the same as above, but with e.g. #[tokio::test] to run async test functions. In that case I would use tokio only as a dev dependency.
Most likely it is a bit too hard to separate canister interface and canister logic. In that case I would suggest you use pocket-ic to write more integration-style tests that compile your canister to wasm and then run tests against it