From nbl.superpowers
Analyzes JaCoCo test coverage in Java Spring projects, identifies gaps in services/managers/controllers/utils, generates missing tests for 80%+ coverage.
npx claudepluginhub icefrag/nbl-superpowers --plugin nbl.superpowersThis skill uses the workspace's default tool permissions.
分析测试覆盖率,识别缺口,生成缺失的测试以达到80%+覆盖率。
Analyzes test coverage reports (lcov, cobertura, istanbul) to identify gaps in lines/branches/functions, map to requirements, recommend tests, and track trends.
Runs coverage tools like pytest-cov and istanbul/c8 via Bash to analyze test coverage, identify gaps, and provide actionable test recommendations.
Analyzes coverage reports from Jest/nyc, pytest, Go test, JaCoCo to find untested paths, branch gaps, low-coverage files, and suggest targeted tests.
Share bugs, ideas, or general feedback.
分析测试覆盖率,识别缺口,生成缺失的测试以达到80%+覆盖率。
| 类型 | 包路径模式 | 测试方式 | 原因 |
|---|---|---|---|
| Service层 | **/service/impl/*Impl.java | 单元测试 | 核心业务逻辑 |
| Manager层 | **/service/manager/impl/*Impl.java | 单元测试 | 外部集成逻辑 |
| Controller层 | **/controller/*.java | 集成测试 | API契约验证 |
| 工具类 | **/utils/*.java(含复杂逻辑) | 单元测试 | 跨服务复用 |
| 财务计算 | 所有含计算逻辑的类 | 单元测试 | 高风险 |
| 认证授权 | **/security/**/*.java | 单元测试 | 安全关键 |
| 类型 | 包路径模式 | 原因 |
|---|---|---|
| Entity类 | **/model/entity/*.java | 纯数据载体,无逻辑 |
| DTO类 | **/model/dto/*.java | 纯数据载体,通过其他测试间接覆盖 |
| Req/Resp/Query | **/model/request/*.java**/model/response/*.java**/model/query/*.java | POJO,通过Controller测试间接覆盖 |
| 枚举类 | **/enums/*.java | 纯定义,无业务逻辑 |
| 常量类 | **/constants/*.java | 仅静态常量 |
| 配置类 | **/config/** | Spring管理,无业务逻辑 |
| Mapper层 | **/mapper/**/*.java | 框架生成实现,通过集成测试间接覆盖 |
| MyBatis拦截器 | **/*.java(implements Interceptor) | MyBatis插件框架,通过集成测试覆盖 |
| 定时任务 | **/job/*.java | 通过集成测试覆盖 |
| 启动类 | *Application.java | 无测试价值 |
| 事件类 | **/*Event.java | 纯数据载体,无业务逻辑 |
| 事件监听器 | **/listener/*Listener.java | Spring框架管理,通过集成测试覆盖 |
| 消息队列监听器 | **/messagequeue/****/mq/** | MQ框架管理,需要真实环境 |
在pom.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>
| 标识 | 覆盖率命令 |
|---|---|
pom.xml with JaCoCo | mvn test jacoco:report |
build.gradle with JaCoCo | ./gradlew test jacocoTestReport |
| 优先级 | 测试类型 | 覆盖目标 |
|---|---|---|
| P0 | 成功路径 | 核心功能使用有效输入 |
| P0 | 异常处理 | 无效输入、业务异常 |
| P1 | 边界案例 | 空集合、null、边界值 |
| P1 | 分支覆盖 | 每个if/else、switch case |
src/test/java/.../src/test/java/.../controller/,使用 nbl.java-spring-integration-testing skill 编写覆盖率报告(已排除Entity/DTO/Mapper/Config类)
──────────────────────────────────────────────────
文件 之前 之后 状态
──────────────────────────────────────────────────
DiscountServiceImpl.java 45% 88% ✅
OrderServiceImpl.java 32% 82% ✅
OrderManagerImpl.java 55% 85% ✅
──────────────────────────────────────────────────
总体覆盖率: 46% 87% ✅
| 代码类型 | 目标覆盖率 | 测试方式 |
|---|---|---|
| 财务计算、认证、安全 | 100% | 单元测试 |
| Service/Manager业务逻辑 | 80%+ | 单元测试 |
| Controller层 | 80%+ | 集成测试 |
| 工具类 | 80%+ | 单元测试 |