nbl.test-coverage
Original:🇨🇳 Chinese
Translated
Test coverage analysis, identify gaps, and generate missing tests to achieve over 80% coverage. Trigger conditions: user requests for test coverage analysis, test coverage improvement, and test writing.
4installs
Sourceicefrag/nbl-superpowers
Added on
NPX Install
npx skill4agent add icefrag/nbl-superpowers nbl.test-coverageTags
Translated version includes tags in frontmatterSKILL.md Content (Chinese)
View Translation Comparison →Test Coverage Skill
Analyze test coverage, identify gaps, and generate missing tests to achieve over 80% coverage.
Activation Timing
- Users request test coverage analysis
- Improve test coverage
- Write missing tests
Step 0: Identify Test Scope (Critical)
✅ Mandatory Testing (100% Coverage Target)
| Type | Package Path Pattern | Testing Method | Reason |
|---|---|---|---|
| Service Layer | | Unit Test | Core business logic |
| Manager Layer | | Unit Test | External integration logic |
| Controller Layer | | Integration Test | API contract verification |
| Utility Classes | | Unit Test | Cross-service reuse |
| Financial Calculation | All classes with calculation logic | Unit Test | High risk |
| Authentication & Authorization | | Unit Test | Security-critical |
🚫 Excluded from Testing (Not counted in coverage)
| Type | Package Path Pattern | Reason |
|---|---|---|
| Entity Classes | | Pure data carrier, no logic |
| DTO Classes | | Pure data carrier, indirectly covered by other tests |
| Req/Resp/Query | | POJO, indirectly covered by Controller tests |
| Enum Classes | | Pure definition, no business logic |
| Constant Classes | | Only static constants |
| Configuration Classes | | Managed by Spring, no business logic |
| Mapper Layer | | Framework-generated implementation, indirectly covered by integration tests |
| MyBatis Interceptors | | MyBatis plugin framework, covered by integration tests |
| Scheduled Jobs | | Covered by integration tests |
| Startup Classes | | No testing value |
| Event Classes | | Pure data carrier, no business logic |
| Event Listeners | | Managed by Spring framework, covered by integration tests |
| Message Queue Listeners | | Managed by MQ framework, requires real environment |
JaCoCo Exclusion Configuration
Configure exclusions in :
pom.xmlxml
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<excludes>
<!-- Entity/DTO/VO -->
<exclude>**/model/entity/**</exclude>
<exclude>**/model/dto/**</exclude>
<exclude>**/model/enums/**</exclude>
<exclude>**/model/request/**</exclude>
<exclude>**/model/response/**</exclude>
<exclude>**/model/query/**</exclude>
<!-- Mapper层 -->
<exclude>**/mapper/**</exclude>
<!-- MyBatis拦截器 -->
<exclude>**/*Interceptor.class</exclude>
<!-- 事件类 -->
<exclude>**/*Event.class</exclude>
<!-- 监听器 -->
<exclude>**/listener/**</exclude>
<!-- 消息队列 -->
<exclude>**/messagequeue/**</exclude>
<exclude>**/mq/**</exclude>
<!-- 配置类 -->
<exclude>**/config/**</exclude>
<!-- 常量类 -->
<exclude>**/constants/**</exclude>
<!-- 启动类 -->
<exclude>**/*Application.class</exclude>
</excludes>
</configuration>
</plugin>Step 1: Detect Test Framework
| Indicator | Coverage Command |
|---|---|
| |
| |
Step 2: Analyze Coverage Report
- Run the coverage command
- Parse the output (target/site/jacoco/jacoco.xml or terminal output)
- After filtering excluded classes, list files with coverage lower than 80%, sorted by lowest coverage first
- For each file with insufficient coverage, identify:
- Untested methods
- Missing branch coverage (if/else, switch, exception paths)
- Dead code (inflates denominator)
Step 3: Generate Missing Tests
Test Priority
| Priority | Test Type | Coverage Target |
|---|---|---|
| P0 | Happy Path | Core functionality with valid input |
| P0 | Exception Handling | Invalid input, business exceptions |
| P1 | Edge Cases | Empty collections, null, boundary values |
| P1 | Branch Coverage | Each if/else, switch case |
Test Generation Rules
- Service/Manager/Utils: Unit tests are placed in
src/test/java/.../ - Controller: Integration tests are placed in
src/test/java/.../controller/ - Follow existing test patterns of the project (import style, assertion library, Mock approach)
- Mock external dependencies (databases, external APIs, file systems)
- Each test should be independent — no mutable state shared between tests
Step 4: Verification
- Run the full test suite — all tests must pass
- Rerun coverage calculation — verify improvements
- If coverage is still below 80%, repeat step 3 to address remaining gaps
Step 5: Report
Coverage Report (Entity/DTO/Mapper/Config classes excluded)
──────────────────────────────────────────────────
File Before After Status
──────────────────────────────────────────────────
DiscountServiceImpl.java 45% 88% ✅
OrderServiceImpl.java 32% 82% ✅
OrderManagerImpl.java 55% 85% ✅
──────────────────────────────────────────────────
Overall Coverage: 46% 87% ✅Coverage Target
| Code Type | Target Coverage | Testing Method |
|---|---|---|
| Financial calculation, authentication, security | 100% | Unit Test |
| Service/Manager business logic | 80%+ | Unit Test |
| Controller Layer | 80%+ | Integration Test |
| Utility classes | 80%+ | Unit Test |