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
Added on

NPX Install

npx skill4agent add icefrag/nbl-superpowers nbl.test-coverage

Tags

Translated version includes tags in frontmatter

SKILL.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)

TypePackage Path PatternTesting MethodReason
Service Layer
**/service/impl/*Impl.java
Unit TestCore business logic
Manager Layer
**/service/manager/impl/*Impl.java
Unit TestExternal integration logic
Controller Layer
**/controller/*.java
Integration TestAPI contract verification
Utility Classes
**/utils/*.java
(with complex logic)
Unit TestCross-service reuse
Financial CalculationAll classes with calculation logicUnit TestHigh risk
Authentication & Authorization
**/security/**/*.java
Unit TestSecurity-critical

🚫 Excluded from Testing (Not counted in coverage)

TypePackage Path PatternReason
Entity Classes
**/model/entity/*.java
Pure data carrier, no logic
DTO Classes
**/model/dto/*.java
Pure data carrier, indirectly covered by other tests
Req/Resp/Query
**/model/request/*.java
<br>
**/model/response/*.java
<br>
**/model/query/*.java
POJO, indirectly covered by Controller tests
Enum Classes
**/enums/*.java
Pure definition, no business logic
Constant Classes
**/constants/*.java
Only static constants
Configuration Classes
**/config/**
Managed by Spring, no business logic
Mapper Layer
**/mapper/**/*.java
Framework-generated implementation, indirectly covered by integration tests
MyBatis Interceptors
**/*.java
(implements Interceptor)
MyBatis plugin framework, covered by integration tests
Scheduled Jobs
**/job/*.java
Covered by integration tests
Startup Classes
*Application.java
No testing value
Event Classes
**/*Event.java
Pure data carrier, no business logic
Event Listeners
**/listener/*Listener.java
Managed by Spring framework, covered by integration tests
Message Queue Listeners
**/messagequeue/**
<br>
**/mq/**
Managed by MQ framework, requires real environment

JaCoCo Exclusion Configuration

Configure exclusions in
pom.xml
:
xml
<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

IndicatorCoverage Command
pom.xml
with JaCoCo
mvn test jacoco:report
build.gradle
with JaCoCo
./gradlew test jacocoTestReport

Step 2: Analyze Coverage Report

  1. Run the coverage command
  2. Parse the output (target/site/jacoco/jacoco.xml or terminal output)
  3. After filtering excluded classes, list files with coverage lower than 80%, sorted by lowest coverage first
  4. 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

PriorityTest TypeCoverage Target
P0Happy PathCore functionality with valid input
P0Exception HandlingInvalid input, business exceptions
P1Edge CasesEmpty collections, null, boundary values
P1Branch CoverageEach 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

  1. Run the full test suite — all tests must pass
  2. Rerun coverage calculation — verify improvements
  3. 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 TypeTarget CoverageTesting Method
Financial calculation, authentication, security100%Unit Test
Service/Manager business logic80%+Unit Test
Controller Layer80%+Integration Test
Utility classes80%+Unit Test