Testing
Different Options
When you run cargo run
, this command compiles the code to binary and then runs the binary. In the same way, cargo test
first compiles to binary code and then runs the test cases
Use cargo test -- --test-threads=1
to run the test in single thread. The --
in between cargo test
and --test-threads=1
is used to run the commands separately for two things.
One for compiling the code to binary and running the binary code
Two for running the binary with specified option
Use cargo test -- show-output
for seeing the println!
output on the console
Use cargo test -- --ignored
to run ignored test cases
Integration Testing
To to integration test in rust, create a new directory tests in the same level as src directory. Then add the test case files inside tests directory.
Each test file inside tests directory creates a crate.
CAVEAT !! IMPORTANT
You can't run integration test cases for functions in src/main.rs. So it is advisable to use src/lib.rs so that we could run integration test cases
Last updated
Was this helpful?