Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can tests be built in release mode using Cargo?

Tags:

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?

like image 780
Fraser Avatar asked Apr 23 '15 08:04

Fraser


People also ask

Does cargo test also build?

Target Selection. When no target selection options are given, cargo test will build the following targets of the selected packages: lib — used to link with binaries, examples, integration tests, and doc tests. bins (only if integration tests are built and required features are available)

Does cargo run tests in parallel?

The default behavior of the binary produced by cargo test is to run all the tests in parallel and capture output generated during test runs, preventing the output from being displayed and making it easier to read the output related to the test results.

What does cargo build do?

Cargo resolves all dependencies of your project, downloads missing dependencies, and compiles it using the rustc compiler. By default, projects are built and compiled in debug mode. For information on compiling your project in release mode, see Building a Rust project in release mode. An existing Rust project.

Where is cargo build output?

Cargo stores the output of a build into the "target" directory. By default, this is the directory named target in the root of your workspace. To change the location, you can set the CARGO_TARGET_DIR environment variable, the build. target-dir config value, or the --target-dir command-line flag.


1 Answers

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.

like image 135
huon Avatar answered Sep 22 '22 17:09

huon