Testing a module
To use the #[marine-test] macro add marine-rs-sdk-test crate to the [dev-dependencies] section of Config.toml:
toml
toml
Let's have a look at an implementation example:
rust
rust
- We wrap a basic greeting function with the #[marine]macro which results in the greeting.wasm module.
- We wrap our tests as usual with [cfg(test)]and import the marine test crate. Do not import super or the local crate.
- Instead, we apply the #[marine_test]macro to each of the test functions by providing the path to the config file, e.g., Config.toml, and the directory containing the Wasm module we obtained after compiling our project withmarine build. Moreover, we add the type of the test as an argument in the function signature. It is imperative that the project build precedes the test runner otherwise the required Wasm file will be missing.
- The target of our tests is the pub fn greetingfunction. Since we are calling the function from the Wasm module we must prefix the function name with the module namespace --greetingin this example case as specified in the function argument.
Now that we have our Wasm module and tests in place, we can proceed with cargo test --release. Note that using the releaseflag vastly improves the import speed of the necessary Wasm modules.
The full example could be found here.