cargo-build-before-test
Detects redundant cargo build steps that immediately precede cargo test with identical build conditions.
This rule looks for:
- a
cargo buildstep - followed within 3 steps by
cargo test - where both commands use the same profile, target, features, package scope, and target selection
- where
cargo testdoes not use--no-run
Why it matters:
cargo testcompiles the required test targets automatically.- A preceding
cargo buildwith identical conditions usually rebuilds the same artifacts and adds avoidable compile time. - On larger Rust repositories this can add noticeable wall-clock and CPU time.
What to do:
- Remove the redundant
cargo buildstep. - If you need an explicit compile phase, use
cargo test --no-runinstead. - Compare job runtime with and without the
cargo buildstep.
Exceptions:
- This rule does not flag when
cargo test --no-runis present, because that explicitly requests a compile-only phase. - This rule does not flag when build conditions differ (profile, target, features, package scope, or target selection), because the build may serve a different purpose.