Fraser
Fraser

Reputation: 78280

Can tests be built in release mode using Cargo?

I'm using cargo build --release to build my project in release configuration and cargo test to build and run my tests.

However, I'd like to also build my tests in release mode; can this be done using cargo?

Upvotes: 46

Views: 19730

Answers (2)

nsf-coding
nsf-coding

Reputation: 66

the closest settings on Cargo.toml to cargo test --release are to append this to the Cargo.toml file:

[profile.test]
inherits = "release"

Then you use cargo test and cargo will do the --release for you.

Upvotes: 2

huon
huon

Reputation: 102016

cargo test --release exists, but it is slightly different than just enabling optimizations. For example, debug assertions become disabled.

You can also set opt-level in the [profile.test] section of your Cargo.toml, as Viktor Dahl suggests.

Upvotes: 52

Related Questions