| name | increasing-code-coverage |
| description | Writes tests to increase code coverage. Activates when the user asks to improve code coverage or to write tests. |
Increasing Code Coverage
Write tests to increase the code coverage in a specific crate. The goal is to increase code coverage to be above 80%.
Rules
- Write unit tests in the same Rust file as the function being tested.
- Write integration tests in the
tests folder inside the crate.
- Create the folder if needed.
- Common helper code goes in
tests/common.rs.
- DO NOT CHANGE THE CRATE CODE WITHOUT USER CONSENT. Only write test code.
- Work on a single crate at the time.
Workflow
Useful commands:
- baseline/summary coverage:
nix develop .#nightly code-coverage -p <crate-name>
- detailed/per file coverage:
nix develop .#nightly code-coverage -p <crate-name> --text
- Get the baseline code coverage for the crate being tested.
- Note which files have the lowest coverage.
- Run the detailed coverage command, focusing on the target files.
- Starting from top level functions, write tests (better if integration tests) for the uncovered functions and paths.
- Run the code coverage summary command again.
- Repeat until the target coverage is reached OR if the coverage stopped increasing.
- Warn the user if the coverage is not increasing despite adding more tests.
Writing tests
- Avoid writing unit tests for simple functions that are covered by integration tests.
- Follow existing testing patterns in the same crate.
- Follow the arrange-act-assert pattern for tests.
- If possible, use the
insta::assert_snapshot! macro to test components that provide structured information through the Display trait, for example DataFusion objects such as LogicalPlan, ExecutionPlan etc.
- DO NOT test code generated by the
#[derive(...)] macro, such as Debug, Clone, Serialize, etc.
- DO NOT test type aliases such as
Ref or Result.
- DO NOT test creating structs for the sake of creating structs. Focus on testing functions.
- Always test error paths too. Use the
insta::assert_debug_snapshot! macro if you need to test the error message/type.
- WARN users about flaky tests.
- Run
cargo clippy -p <crate-name> --tests and fix any issues.