unit-testing
Guidelines for writing effective JUnit5 and MockK unit tests with an emphasis on TDD and dependency mocking.
Install
mkdir -p .claude/skills/unit-testing && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/1686" && unzip -o skill.zip -d .claude/skills/unit-testing && rm skill.zipInstalls to .claude/skills/unit-testing
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
为 BK-CI 代码编写单元测试时使用,例如 JUnit5、MockK、测试组织、依赖 Mock、异常校验和 TDD 场景。当用户要补测试或用测试驱动实现时优先使用。Key capabilities
- →Write unit tests for Service, DAO, and utility classes
- →Mock external dependencies and boundary conditions
- →Verify normal paths, exception paths, and regression scenarios
- →Apply Test-Driven Development (TDD) practices
- →Ensure representative coverage for normal and failure paths
- →Isolate boundaries through mocking
How it works
This skill guides the creation of unit tests using patterns like AAA, mocking external dependencies, and explicit assertions. It focuses on testing business rules and ensuring coverage for critical paths and regression risks.
Inputs & outputs
When to use unit-testing
- →Write service layer unit tests
- →Mock external system dependencies
- →Implement TDD workflows
- →Increase test coverage for critical paths
About this skill
单元测试
适用场景
- 编写 Service / DAO / 工具类单元测试
- Mock 外部依赖和边界条件
- 验证正常路径、异常路径和回归场景
- 采用 TDD 或补测试防回归
不适用场景
- 集成测试、端到端测试
- 只是实现业务逻辑,不准备补测试
- 只是排查运行环境问题
快速指导
- 这个 skill 关注的是 BK-CI 项目里的单元测试写法,不是测试理论总览。
- 测试先保证意图清晰,再考虑覆盖率;重点是关键分支和回归风险。
- 常见模式仍然是 AAA、Mock 外部依赖、显式断言结果和交互。
- 写测试前先确认你测的是业务规则,不是把实现细节机械复述一遍。
- 如果测试涉及后端接口或服务结构,再联动看
backend-microservice-development。
高信号规则
- 正常路径和失败路径都要有代表性覆盖
- Mock 应该服务于隔离边界,而不是掩盖设计问题
- 测试命名要能直接表达行为和预期
关键陷阱
- 只测 happy path
- Mock 过度,导致测试几乎失去行为价值
- 断言太弱,只证明代码跑过,没有证明结果正确
延伸阅读
- 如果你在改后端服务:再看
backend-microservice-development
When not to use it
- →For integration tests or end-to-end tests
- →When only implementing business logic without adding tests
- →When troubleshooting runtime environment issues
Limitations
- →The skill focuses on unit testing practices for the BK-CI project.
- →It does not cover integration testing or end-to-end testing.
How it compares
This skill provides specific guidelines for writing unit tests, including naming conventions and mocking techniques, rather than just general testing theory.
Compared to similar skills
unit-testing side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| unit-testing (this skill) | 3 | 3mo | No flags | Beginner |
| springboot-verification | 4 | 4mo | Review | Intermediate |
| mocking | 0 | 5mo | No flags | Beginner |
| code-checklist | 0 | 4mo | Review | Beginner |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by TencentBlueKing
View all by TencentBlueKing →You might also like
springboot-verification
affaan-m
Verification loop for Spring Boot projects: build, static analysis, tests with coverage, security scans, and diff review before release or PR.
mocking
comeredon
Mockito mocking patterns for isolating units under test. Use when testing classes with external dependencies like databases, files, or APIs.
code-checklist
comeredon
Critical code requirements checklist derived from actual build failures. Use before committing code or when troubleshooting compilation errors.
migration-unit-testing
RobertoBorges
|
springboot-tdd
affaan-m
Test-driven development for Spring Boot using JUnit 5, Mockito, MockMvc, Testcontainers, and JaCoCo. Use when adding features, fixing bugs, or refactoring.
review-pr
apache
Used to review whether an Apache ShardingSphere PR truly fixes the root cause, assess side effects and regression risks, and determine whether it can be safely merged. If not mergeable, produce committer-tone change request suggestions. Supports targeted comparison across multiple review rounds.