Hi all :wave: I am struggling to understand how to create unit tests for the wasm32-wasip2 target with wit-bindgen-generated code.
My current understanding is that the generated code only runs with the wasm32 target/arch, so you can't just use the generated code in regular unit tests (when you cargo testyou hit unreachable!()).
So the question is: how do I create unit tests for Rust components? So far we've tried to unit-test the core business logic that doesn't depend on WASI stuff, but that doesn't feel great. We'd like to reach good test coverage. Is there a way to run unit tests with compiled code?
in .cargo/config.toml, add
[target.wasm32-wasip2]
runner = "wasmtime run"
and then cargo test --target wasm32-wasip2 will execute the tests in wasmtime.
thank you @Pat Hickey :pray: because I need the http WASI implementation, I managed to get it to work with:
[target.wasm32-wasip2]
runner = "wasmtime run --wasi http=y"
Unfortunately, it doesn't seem possible to generate coverage data via cargo llvm-cov :sad: https://github.com/taiki-e/cargo-llvm-cov/issues/221
Related: https://github.com/rust-lang/rust/issues/81684
I also looked into https://github.com/hknio/wasmcov but that seems out of scope for WASI :thinking:
Any ideas?
shorthand there would be wasmtime run -Shttp, glad it worked.
and no, I don't have any recommendations for measuring code coverage.
Last updated: Dec 06 2025 at 05:03 UTC