cargo-test:tldr:f1292
The command cargo test --locked
is used to run tests in a Rust project with the dependency versions locked.
In Rust projects managed by Cargo, the Cargo.lock
file is used to record the exact versions of dependencies that were resolved and used during development. By default, when running tests, Cargo updates the dependencies to their latest compatible versions, based on the information in the Cargo.toml
file. This ensures that tests are run with the most up-to-date dependencies.
However, sometimes it is desirable to execute tests with the exact same dependency versions as recorded in the Cargo.lock
file. This can be useful in situations where you want to guarantee consistent and reproducible test results across different environments or when collaborating with other developers.
The --locked
flag tells Cargo to use the locked dependency versions when running tests. With this flag, Cargo will ignore the Cargo.toml
file regarding dependency resolution and instead use the exact versions specified in Cargo.lock
. This ensures that the tests are executed with the same dependency versions that were previously resolved and recorded.
To summarize, cargo test --locked
is used to run tests with the exact dependency versions specified in the Cargo.lock
file, providing consistent and reproducible test results.