Testing

Chester Wyke November 05, 2023 Updated: April 15, 2025 #rust

Frequently used links and commands

Mostly self explanatory except that running test in release mode can increase limits for things like stack overflow

For more information about these commands see cargo test -- --help.

cargo test -- --nocapture
cargo test -- --show-output # Seems to also show output that is not tied to a specific test (so needed sometimes)
cargo test -- --ignored
cargo test -r
cargo add --dev rstest
cargo add --dev strum -F derive,strum_macros

Shared module for integration tests

Source: https://doc.rust-lang.org/book/ch11-03-test-organization.html#submodules-in-integration-tests

Do tests/common/mod.rs and not tests/common.rs.

Click for details!

They mainly focus the extra 0 test cases that show in the output, and yes that’s annoying but what annoyed me more was the warnings that functions are not used as each file is compiled separately. So if warnings bother you too then you probably want to ensure you ensure you put it in mod.rs.

Testing CLI applications by running them

Source: https://rust-cli.github.io/book/tutorial/testing.html#testing-cli-applications-by-running-them

Don’t have more detailed notes other than the link because I decided to not actually run the program but just test the lib instead as the compiler will guide me to where updates need to happen instead of needing to run the test to see where updates are needed. But saving the link because I’ve looked it up quite a few times.