skills/backend-unit-test/SKILL.md
后端单元测试技能。触发场景: - 用户要求运行/创建单元测试 - 用户要求验证数据 - 用户要求用 Maven 运行测试 - 关键词:test, maven test, junit, springboot test, 单元测试, 测试验证 核心:不改 pom,用 reactor 模式运行。
npx skillsauth add dwsy/agent backend-unit-testInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
# 步骤1: 编译测试类
cd sfm_back && mvn compiler:testCompile -pl <module> -am
# 步骤2: 运行测试
cd sfm_back && mvn surefire:test -pl <module> -am -Dtest="测试类名"
| 参数 | 作用 |
|------|------|
| -pl <module> | 指定模块,如 med-ams、med-bpm-biz |
| -am | 连带构建依赖模块(reactor 模式),不经过 install |
| -Dtest="xxx" | 指定测试类,支持通配符 * |
# 编译 + 运行 med-ams 模块测试
cd sfm_back && mvn compiler:testCompile -pl med-ams -am
cd sfm_back && mvn surefire:test -pl med-ams -am -Dtest="AmsPropertyReadServiceTest"
# 使用通配符运行多个测试
cd sfm_back && mvn surefire:test -pl med-ams -am -Dtest="AmsPropertyReadService*"
# 运行所有测试
cd sfm_back && mvn surefire:test -pl med-ams -am -Dtest="*Test"
<module>/src/test/
├── java/com/jp/med/<module>/modules/<功能>/<ServiceTest>.java
└── resources/application.yml
package com.jp.med.<module>.modules.<功能>;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.transaction.annotation.Transactional;
import static org.junit.jupiter.api.Assertions.*;
@SpringBootTest
@ActiveProfiles("unit-test")
@Transactional
class <ServiceTest> {
@Autowired(required = false)
private <Service> targetService;
@Test
void contextLoads() {
assertNotNull(targetService, "服务应该被注入");
}
}
# src/test/resources/application.yml
spring:
main:
lazy-initialization: true
banner-mode: off
jdbc:postgresql://localhost:5432/jp_db_20260305@Transactional 确保测试数据自动回滚| 问题 | 原因 | 解决 |
|------|------|------|
| No tests executed | 测试类未编译 | 先 compiler:testCompile |
| 编译失败 | import 错误 | 检查包路径是否与目录匹配 |
| med-common 依赖错误 | clean 后资源被清理 | 避免 clean,直接编译 |
| Test run: 0 | 测试类名不匹配 | 确认类名或使用通配符 * |
mvn installmvn clean(触发资源过滤问题)-am 参数确保依赖正确构建find sfm_back -path "*/test/*" -name "*Test.java"mvn compiler:testCompile -pl <module> -ammvn surefire:test -pl <module> -am -Dtest="TestName"Tests run: X, Failures: 0, Errors: 0testing
Best practices for writing and maintaining high-quality role memories.
documentation
工作文档枢纽,强制执行 SSOT(Single Source of Truth)原则,管理 `docs/` 目录下的架构决策、设计文档、Issues(任务规划)、PRs(变更记录)。支持 GitHub 协作开发模式。
tools
Allows to interact with web pages by performing actions such as clicking buttons, filling out forms, and navigating links. It works by remote controlling Google Chrome or Chromium browsers using the Chrome DevTools Protocol (CDP). When Claude needs to browse the web, it can use this skill to do so.
development
Vercel 设计指南 - 构建高质量 Web 应用的最佳实践,包含现代 UI/UX 原则、性能优化和无障碍标准。