Cargo "could not compile X (test profile)" in CI
The crate compiled fine for a normal build but failed when compiled with the test profile. Test-only code -- #[cfg(test)] modules, dev-dependencies, #[test] functions -- has a compile error, so cargo test aborts before running anything.
What this error means
The build reports error: could not compile X (lib test) (or "(bin test)") with the underlying compile error above it. cargo build passes while cargo test fails.
error[E0433]: failed to resolve: use of undeclared crate or module `proptest`
--> src/lib.rs:40:9
|
40 | use proptest::prelude::*;
| ^^^^^^^^ use of undeclared crate or module `proptest`
error: could not compile `app` (lib test) due to previous errorCommon causes
Test-only code does not compile
A #[cfg(test)] module references a dev-dependency that is missing, or has its own type error that only the test profile triggers.
Missing dev-dependency
A crate used only in tests is not listed under [dev-dependencies], so it resolves in your editor (via a normal dep) but not under the test profile.
How to fix it
Add the missing dev-dependency
# Cargo.toml
[dev-dependencies]
proptest = "1"Compile the test profile locally
cargo test --no-run builds tests without executing them, surfacing the compile error fast.
cargo test --no-run --lockedHow to prevent it
- Run
cargo test --no-runin CI (or locally) to catch test-profile breakage. - List every test-only crate under
[dev-dependencies]. - Keep
#[cfg(test)]modules building as part of your normal check loop.