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.zip

Installs 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 场景。当用户要补测试或用测试驱动实现时优先使用。
83 charsno explicit “when” trigger
Beginner

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

You give it
Code requiring unit tests, external dependencies to mock, or a need to improve test coverage
You get back
Unit tests following AAA pattern, mocked dependencies, and verified code behavior

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 或补测试防回归

不适用场景

  • 集成测试、端到端测试
  • 只是实现业务逻辑,不准备补测试
  • 只是排查运行环境问题

快速指导

  1. 这个 skill 关注的是 BK-CI 项目里的单元测试写法,不是测试理论总览。
  2. 测试先保证意图清晰,再考虑覆盖率;重点是关键分支和回归风险。
  3. 常见模式仍然是 AAA、Mock 外部依赖、显式断言结果和交互。
  4. 写测试前先确认你测的是业务规则,不是把实现细节机械复述一遍。
  5. 如果测试涉及后端接口或服务结构,再联动看 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.

SkillInstallsUpdatedSafetyDifficulty
unit-testing (this skill)33moNo flagsBeginner
springboot-verification44moReviewIntermediate
mocking05moNo flagsBeginner
code-checklist04moReviewBeginner

Try saying

Example prompts that trigger this skill in your AI assistant.

More by TencentBlueKing

View all by TencentBlueKing

project-module-architecture

TencentBlueKing

Project 项目管理模块架构指南,涵盖项目 CRUD、成员管理、项目配置、标签管理、项目迁移。当用户开发项目管理功能、处理项目成员、配置项目属性或实现项目相关逻辑时使用。

612

artifactory-module-architecture

TencentBlueKing

Artifactory 制品库模块架构指南,涵盖制品上传下载、存储后端适配、制品元数据、清理策略、权限控制。当用户开发制品库功能、处理制品存储、配置清理策略或实现制品管理时使用。

419

microservice-infrastructure

TencentBlueKing

微服务基础设施指南,涵盖条件配置、事件驱动架构、服务间通信、国际化与日志等微服务架构的核心基础设施。当用户实现服务间调用、配置多环境、实现异步通信、处理国际化或规范日志输出时使用。

411

frontend-vue-development

TencentBlueKing

前端 Vue 开发规范,涵盖 Vue 2/3 组件开发、Vuex 状态管理、路由配置、组件通信、样式规范、国际化。当用户进行前端开发、编写 Vue 组件、处理状态管理或实现页面交互时使用。

38

worker-module-architecture

TencentBlueKing

Worker 构建执行器模块架构指南,涵盖插件执行引擎、任务分发、日志上报、制品上传、Worker 生命周期。当用户开发 Worker 功能、实现插件执行、处理任务分发或优化执行器性能时使用。

37

agent-module-architecture

TencentBlueKing

Agent 构建机模块架构指南(Go 语言),涵盖 Agent 启动流程、心跳机制、任务领取执行、升级更新、与 Dispatch 交互。当用户开发 Agent 功能、修改心跳逻辑、处理任务执行或实现 Agent 升级时使用。

23

Search skills

Search the agent skills registry