Skill: Improve Code Coverage
This skill guides you through the process of systematically and incrementally improving code coverage in the ComposeLife project by adding realistic unit tests.
Step-by-Step Workflow
1. Ask for Target Count
At the start of the task, ask the user:
"How many low-coverage areas would you like to improve?"
Get the number $N$ from the user.
2. Generate and Parse Baseline Coverage
- Ensure a fresh coverage report is built by running:
./gradlew jacocoDebugUnitTestCoverageReport
- Parse the Jacoco XML report by running the helper script:
python3 .agents/skills/improve-code-coverage/scripts/parse_jacoco.py
This will output a sorted list of classes by missed instructions to build/jacoco_report.txt.
3. Create the Plan
- Select the top $N$ classes from the report that fit these criteria:
- Very low existing coverage.
- More likely to be user-visible behavior (e.g. settings, geometric extension functions, state management).
- Core algorithms or serialization code.
- Formulate an ordered list of these $N$ areas.
- Draft a plan similar to
test_coverage_plan.md listing the baseline coverage and the targeted test files.
- Present this plan to the user for approval.
4. Implement Improvements Incrementally (1:1)
For each area in the plan, perform the following steps:
A. Find Missed Lines
Run the line lookup script to identify the exact lines and branches that are not covered:
python3 .agents/skills/improve-code-coverage/scripts/find_missed_lines.py <SourceFileName.kt>
B. Write Realistic Unit Tests
- Locate the corresponding test directory (e.g.,
jbTest, commonTest, jvmTest under the same module).
- Write unit tests targeting the missed functions/lines.
- CRITICAL: Adhere strictly to the project style rules enforced by Detekt to prevent CI compilation failures:
- Trailing Commas: Add trailing commas to all multi-line function calls, parameter lists, and declarations (e.g., lists of arguments or elements).
- Line Length: Ensure no line of code exceeds 120 characters. Assign long expressions to local variables if they would wrap awkwardly.
- Import Ordering: Keep all imports sorted lexicographically, with no empty lines between them. Group
kotlin.*, kotlinx.*, okio.* correctly, and put kotlin.* imports at the end of the imports block.
- Function and Class Sizes: Avoid test methods longer than 60 lines (Detekt
LongMethod). Avoid test classes with too many functions (or apply @Suppress("TooManyFunctions") to the class declaration).
- Unit Testing Framework: Use
kotlin.test APIs (assertEquals, assertTrue, assertFalse, assertNotEquals<Any?>, etc.) rather than JUnit.
C. Run the Module Tests
- Run the target-specific host tests rather than generic long-running tasks. For example, for the
navigation module:./gradlew :navigation:testAndroidHostTest
- Verify that all tests pass. If compiling or test failures occur, fix them.
D. Regenerate Coverage and Verify
- Run the report task:
./gradlew jacocoDebugUnitTestCoverageReport
- Parse the report and verify that instruction and branch coverage improved for the target class.
E. Commit and Fixup
- Create a git commit with a message specifying:
- The area/class improved.
- The coverage improvement metrics (X% from Y%, and missed branches reduced to A from B).
- What behavior wasn't previously covered.
- If minor formatting fixes or code style changes are needed after feedback or check failures, stage the fixes and commit them with
--fixup targeting the original commit, like:git commit --fixup <commit-hash>
5. Final Verification
After all $N$ areas are implemented, run:
./gradlew check
Verify that all CI checks, tests, and Detekt inspections pass successfully.
Source: alexvanyo/composelife — distributed by TomeVault.
1---2name: alexvanyo-composelife-composelife3description: Skill: Improve Code Coverage4---56# Skill: Improve Code Coverage78This skill guides you through the process of systematically and incrementally improving code coverage in the **ComposeLife** project by adding realistic unit tests.910## Step-by-Step Workflow1112### 1. Ask for Target Count13At the start of the task, ask the user:14> "How many low-coverage areas would you like to improve?"15Get the number $N$ from the user.1617### 2. Generate and Parse Baseline Coverage181. Ensure a fresh coverage report is built by running:19 ```bash20 ./gradlew jacocoDebugUnitTestCoverageReport21 ```222. Parse the Jacoco XML report by running the helper script:23 ```bash24 python3 .agents/skills/improve-code-coverage/scripts/parse_jacoco.py25 ```26 This will output a sorted list of classes by missed instructions to `build/jacoco_report.txt`.2728### 3. Create the Plan291. Select the top $N$ classes from the report that fit these criteria:30 - Very low existing coverage.31 - More likely to be user-visible behavior (e.g. settings, geometric extension functions, state management).32 - Core algorithms or serialization code.332. Formulate an ordered list of these $N$ areas.343. Draft a plan similar to `test_coverage_plan.md` listing the baseline coverage and the targeted test files.354. Present this plan to the user for approval.3637### 4. Implement Improvements Incrementally (1:1)38For each area in the plan, perform the following steps:3940#### A. Find Missed Lines41Run the line lookup script to identify the exact lines and branches that are not covered:42```bash43python3 .agents/skills/improve-code-coverage/scripts/find_missed_lines.py <SourceFileName.kt>44```4546#### B. Write Realistic Unit Tests471. Locate the corresponding test directory (e.g., `jbTest`, `commonTest`, `jvmTest` under the same module).482. Write unit tests targeting the missed functions/lines.493. **CRITICAL:** Adhere strictly to the project style rules enforced by Detekt to prevent CI compilation failures:50 - **Trailing Commas:** Add trailing commas to all multi-line function calls, parameter lists, and declarations (e.g., lists of arguments or elements).51 - **Line Length:** Ensure no line of code exceeds **120 characters**. Assign long expressions to local variables if they would wrap awkwardly.52 - **Import Ordering:** Keep all imports sorted lexicographically, with no empty lines between them. Group `kotlin.*`, `kotlinx.*`, `okio.*` correctly, and put `kotlin.*` imports at the end of the imports block.53 - **Function and Class Sizes:** Avoid test methods longer than **60 lines** (Detekt `LongMethod`). Avoid test classes with too many functions (or apply `@Suppress("TooManyFunctions")` to the class declaration).54 - **Unit Testing Framework:** Use `kotlin.test` APIs (`assertEquals`, `assertTrue`, `assertFalse`, `assertNotEquals<Any?>`, etc.) rather than JUnit.5556#### C. Run the Module Tests571. Run the target-specific host tests rather than generic long-running tasks. For example, for the `navigation` module:58 ```bash59 ./gradlew :navigation:testAndroidHostTest60 ```612. Verify that all tests pass. If compiling or test failures occur, fix them.6263#### D. Regenerate Coverage and Verify641. Run the report task:65 ```bash66 ./gradlew jacocoDebugUnitTestCoverageReport67 ```682. Parse the report and verify that instruction and branch coverage improved for the target class.6970#### E. Commit and Fixup711. Create a git commit with a message specifying:72 - The area/class improved.73 - The coverage improvement metrics (X% from Y%, and missed branches reduced to A from B).74 - What behavior wasn't previously covered.752. If minor formatting fixes or code style changes are needed after feedback or check failures, stage the fixes and commit them with `--fixup` targeting the original commit, like:76 ```bash77 git commit --fixup <commit-hash>78 ```7980### 5. Final Verification81After all $N$ areas are implemented, run:82```bash83./gradlew check84```85Verify that all CI checks, tests, and Detekt inspections pass successfully.8687---88> Source: [alexvanyo/composelife](https://github.com/alexvanyo/composelife) — distributed by [TomeVault](https://tomevault.io).89<!-- tomevault:4.0:skill_md:2026-06-30 -->