Search code examples
rustrust-cargo

How to only build the tests using cargo?


Is there a way to only build and not run tests using cargo? When i run cargo build it doesn't build the test targets, and cargo test will start running the tests as well.

The reason I want to only build the tests is because i'm debugging a test under a debugger. So I just want to edit+build on a different terminal and re-run that test target from inside the debugger session.


Solution

  • cargo test --no-run

    This will output the executable name(s). If you want to automate this, you can append --message-format json to get this in a machine-readable format.