I want to package up a specific unit test into an executable binary that I can run myself under a debugger.
How can I do this with cargo?
Running cargo test
results in the following output:
❯ cargo test
Compiling mycrate v0.1.0 (mycrate)
Finished test [unoptimized + debuginfo] target(s) in 0.44s
Running target/debug/deps/mycrate-1a3af12dafb80133
running tests...
As you can see by this line:
Running target/debug/deps/mycrate-1a3af12dafb80133
The test actually is a standalone executable, located in target/debug/deps/
.
You can run the executable directly:
❯ ./target/debug/deps/mycrate-1a3af12dafb80133
running tests...
You can also build the executable without running the tests with the no-run
flag:
❯ cargo test --no-run
Compiling mycrate v0.1.0 (mycrate)
Finished test [unoptimized + debuginfo] target(s) in 0.41s
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With