java-unit-test SKILL.md skillA

java-unit-test from baixuanzhu/skills is an agent skill: a SKILL.md folder an AI agent loads when a task calls for it.

Install it, pinned
mdr add baixuanzhu/skills/java-unit-test@v2.2.0

Pins v2.2.0 in mdr.lock. Pin the fingerprint instead.

Audit grade
A, 17 of 17 checks passed
Kind
SKILL.md skill
Repository
baixuanzhu/skills
Path
skills/java-unit-test/SKILL.md
Versions recorded
5
Latest version
v2.2.0, committed Oct 24, 2026
First version recorded
Oct 4, 2026
Size
7,156 bytes
Repository stars
3
License
MIT

Java 开发期测试(纯单元测试)助手——@Mock + @InjectMocks 或项目既有的 @TestConfiguration 轻量 mock 装配,AssertJ 断言,毫秒级,零外部基础设施 (不连真实 DB / 容器 / 中间件)。在编写、评审、补全、重构单元测试时使用 本技能,无论用户是否提到具体框架(unit test / JUnit / Mockito / 测试用例 / 怎么测 / 测哪些 / 写多少)。 次级触发信号——代码或 pom 中出现:spring-boot-starter-test、junit-jupiter、 @Test / @BeforeEach / @ParameterizedTest / @MethodSource、 assertEquals(new BigDecimal、BigDecimal 比金额、 assertThat / isEqualByComparingTo / assertThatThrownBy(AssertJ)、 @Mock / @InjectMocks / MockitoAnnotations.openMocks、spy…

Collected from public GitHub. Every version is saved exactly as it was and never changes. Install it at an exact version with the mdr tool, and every file is checked before it reaches your agent. The main file is checked against the SHA-256 fingerprint recorded here, and the others against the fingerprints GitHub keeps for its source commit. The automatic checks below grade the latest version, and the same checks always give the same file the same grade.

What the file says

# Java 开发期测试

开发期测试 = **纯单元测试**:被测对象是真实对象,外部依赖用 mock,毫秒级,`mvn test` / `gradle test` 秒级跑完——零外部基础设施(不连真实 DB / 容器 / 中间件)。默认 `@Mock`+`@InjectMocks`;项目既有 `@TestConfiguration` 手写 `@Bean` mock + `@Import` 的轻量装配惯例时跟随,但上下文里只允许 mock 与纯内存对象。

> 接口级验证("接口通不通")不写测试、不属本技能范围;需要真实依赖断言 / 可重复回归的集成测试 → java-integration-test,明示或确认后激活。

## 唯一判据:把被测代码改坏,这条测试会红吗

答不出会红在哪一行,这条测试就是装饰品。写测试代码不难,难的是知道自己写的测试**在什么情况下是假的**。三个检查点覆盖全部已知假绿来源,命中任一条读 `references/01-pitfalls.md`。

### 一、mock 注入的,是被测代码真正用的那个实例吗

| 断在哪 | 表现 |
|---|---|
| 被测类内部 `new` 依赖 | mock 注入的是另一个实例,被测代码安静地用自己的,断言对着假对象跑,全程无报错。判别:桩值没生效 / `verify` 从不命中 / 断言全过 → 先查 `new` |
| 对 `spy` 用 `when()` 打桩 | `when()` 先执行真实方法,副作用已经发生,再回放桩值。真实方法有副作用时,失败点漂移到毫不相干的断言上 |
| `mockStatic` 不包 `try-with-resources` | 静态 mock 泄漏到同线程后续测试,失败点漂移到别的类 |

`LocalDate.now()` / `UUID.randomUUID()` / `new ObjectMapper()` 这类调用点在**你自己代码里**就不算够不着——注入 `Clock.fixed(...)` 或 `IdGenerator` 接口,不要上 `mockStatic`。

### 二、断言比的,是你真正要保证的东西吗

| 断在哪 | 表现 |
|---|---|
| 金额用 `assertEquals(BigDecimal, BigDecimal)` | `equals` 连 scale 一起比。scale 恰好一致时全绿,把「金额固定两位小数」这个要求掩盖了;真正该固定的小数位反而没人管 |
| 异常断在 `RuntimeException` / `Exception` 根父类 | 任何异常都满足,被测代码抛 NPE 也算通过。断契约指定的具体类 + `hasMessage` |
…

Read the whole file at its exact version.

How to install

The exact contents, by fingerprint
mdr add baixuanzhu/skills/java-unit-test@sha256:0909dee51cb5f4a1

The line at the top of this page pins the label v2.2.0, which is what most people want. This one pins the sha256 fingerprint of the contents instead, so it survives a label being moved. Either way the exact version is written to mdr.lock, and mdr install downloads and checks those contents again, so it installs them exactly or stops with an error.

Badge

mdr badge

[![mdr](https://markdownregistry.com/badge/art_fb5nfodubt7tkwpx.svg)](https://markdownregistry.com/a/art_fb5nfodubt7tkwpx)

5 badge image fetches in 30 days. What the badge shows.

Versions

The registry has recorded 5 versions of this file, between Oct 4, 2026 and Oct 24, 2026, about one every 5 days.

versioncommittedcommitsizeaudit
v2.2.0 latest2026-10-24 95aa2f2 7,156 BA view · diff
v2.1.12026-10-24 d3663e1 7,480 BA view · diff
v2.1.02026-10-24 9d5c0e9 7,609 BA view · diff
v2.0.02026-10-04 b24ce00 11,889 BA view · diff
v2.0.02026-10-04 13088df 11,833 BA view

Audit of the latest version

A  17 of 17 checks passed. Fixed automatic checks with no AI involved, so the same checks give the same answer every run.
  • pass: Frontmatter block present
  • pass: Frontmatter declares a name
  • pass: Frontmatter declares a description
  • pass: Size between 200 bytes and 200 KB (7156 bytes)
  • pass: No zero-width or bidi control characters
  • pass: No instruction hidden inside an HTML comment
  • pass: No link to an exfiltration or paste host
  • pass: No credential-shaped string
  • pass: No instruction to send local credentials anywhere
  • pass: No text hidden with inline styles
  • pass: No prompt-injection phrasing
  • pass: No curl or wget piped into a shell
  • pass: No recursive delete of root, home or parent
  • pass: No instruction to read or print local credentials
  • pass: No base64 blob over 200 characters
  • pass: No link to a raw IP address
  • pass: No script tag

Source

GitHub

baixuanzhu/skills · 3 stars · license MIT · pushed 2026-11-03 · branch main

API

GET https://markdownregistry.com/api/v1/artifacts/art_fb5nfodubt7tkwpx
GET https://markdownregistry.com/api/v1/resolve?ref=baixuanzhu/skills/java-unit-test
GET https://markdownregistry.com/api/v1/blob/0909dee51cb5f4a1eeb7cf23ddb938adc99ba9dd88424608b1d14a747a9eaa6f

Your AI assistant does the legwork. You hear about the deals worth your word. Hand yours the standing instructions at modelranch.com and it joins the network that reads files like this one.

Guides: the SKILL.md format and its required fields · what to check before you install a skill · how to pin a skill to an exact version · where to find agent skills · keeping a team on the same skills · which agent file does what.

More from baixuanzhu/skills

AGENTS.md AGENTS.md file
baixuanzhu/skills · AGENTS.md
git:20261027.6a2cc9a · audit A · 3 stars
CLAUDE.md CLAUDE.md file
baixuanzhu/skills · CLAUDE.md
git:20260822.070edce · audit B · 3 stars
java-coding-guide-pro SKILL.md skill
baixuanzhu/skills · eval/java-coding-guide-pro/darwin-validation-v3.4.0/snapshots/v3.3.0/SKILL.md · Java 编码规范与避坑助手。在编写、修改、重构或审查任何 Java / Spring Boot 代码时使用本技能—— 无论用户是否提到编码规范或具体工具库(Java coding / code review / refactoring…
v3.3.0 · audit A · 3 stars
java-coding-guide-pro SKILL.md skill
baixuanzhu/skills · eval/java-coding-guide-pro/darwin-validation-v3.4.0/snapshots/v3.4.0/SKILL.md · Java 编码规范与避坑助手。在编写、修改、重构或审查任何 Java / Spring Boot 代码时使用本技能—— 无论用户是否提到编码规范或具体工具库(Java coding / code review / refactoring…
v3.4.0 · audit A · 3 stars
java-coding-guide-pro SKILL.md skill
baixuanzhu/skills · eval/java-coding-guide-pro/darwin-validation-v3.4.0/snapshots/version1/SKILL.md · Java 编码规范与避坑助手。在编写、修改、重构或审查任何 Java / Spring Boot 代码时使用本技能—— 无论用户是否提到编码规范或具体工具库(Java coding / code review / refactoring…
v3.3.0 · audit A · 3 stars
java-coding-guide-pro SKILL.md skill
baixuanzhu/skills · eval/java-coding-guide-pro/darwin-validation-v3.4.0/snapshots/version2/SKILL.md · Java 编码规范与避坑助手。在编写、修改、重构或审查任何 Java / Spring Boot 代码时使用本技能—— 无论用户是否提到编码规范或具体工具库(Java coding / code review / refactoring…
v3.4.0 · audit A · 3 stars
java-coding-guide-pro SKILL.md skill
baixuanzhu/skills · eval/java-coding-guide-pro/darwin-validation-v3.4.0/snapshots/versionA/SKILL.md · Java 编码规范与避坑助手。在编写、修改、重构或审查任何 Java / Spring Boot 代码时使用本技能—— 无论用户是否提到编码规范或具体工具库(Java coding / code review / refactoring…
v3.4.0 · audit A · 3 stars
java-coding-guide-pro SKILL.md skill
baixuanzhu/skills · eval/java-coding-guide-pro/darwin-validation-v3.4.0/snapshots/versionB/SKILL.md · Java 编码规范与避坑助手。在编写、修改、重构或审查任何 Java / Spring Boot 代码时使用本技能—— 无论用户是否提到编码规范或具体工具库(Java coding / code review / refactoring…
v3.3.0 · audit A · 3 stars
java-coding-guide-pro SKILL.md skill
baixuanzhu/skills · eval/java-coding-guide-pro/darwin-validation-v3.5.0/snapshots/v3.4.1/SKILL.md · Java 编码规范与避坑助手。在编写、修改、重构或审查任何 Java / Spring Boot 代码时使用本技能—— 无论用户是否提到编码规范或具体工具库(Java coding / code review / refactoring…
v3.4.1 · audit A · 3 stars
java-coding-guide-pro SKILL.md skill
baixuanzhu/skills · eval/java-coding-guide-pro/darwin-validation-v3.5.0/snapshots/v3.5.0/SKILL.md · Java 编码规范与避坑助手。在编写、修改、重构或审查任何 Java / Spring Boot 代码时使用本技能—— 无论用户是否提到编码规范或具体工具库(Java coding / code review / refactoring…
v3.5.0 · audit A · 3 stars
java-coding-guide-pro SKILL.md skill
baixuanzhu/skills · eval/java-coding-guide-pro/darwin-validation-v3.5.0/snapshots/version1/SKILL.md · Java 编码规范与避坑助手。在编写、修改、重构或审查任何 Java / Spring Boot 代码时使用本技能—— 无论用户是否提到编码规范或具体工具库(Java coding / code review / refactoring…
v3.4.1 · audit A · 3 stars
java-coding-guide-pro SKILL.md skill
baixuanzhu/skills · eval/java-coding-guide-pro/darwin-validation-v3.5.0/snapshots/version2/SKILL.md · Java 编码规范与避坑助手。在编写、修改、重构或审查任何 Java / Spring Boot 代码时使用本技能—— 无论用户是否提到编码规范或具体工具库(Java coding / code review / refactoring…
v3.5.0 · audit A · 3 stars

Every file in baixuanzhu/skills

Other files named java-unit-test

java-unit-test SKILL.md skill
hashgraph-online/awesome-codex-plugins · plugins/Colin4k1024/tsp/skills/java-unit-test/SKILL.md · 为 Spring Boot 项目生成高质量 Java 单元测试代码。当用户要求"写单元测试"、"生成测试用例"、"帮我写 test"、"补充测试覆盖"、"写 JUnit 测试"、"写 Mockito 测试"、"测试这个 Service /…
git:20260512.6523792 · audit A · 1,537 stars
java-unit-test SKILL.md skill
baixuanzhu/skills · eval/java-unit-test/regression-v1.5.0/snapshots/version2/SKILL.md · Java 单元测试助手。在编写、评审、补全、重构单元测试时使用本技能—— 无论用户是否提到具体框架(unit test / JUnit / Mockito / 测试用例 / 怎么测 / 测哪些 / 写多少)。 次级触发信号——代码或…
v1.5.0 · audit A · 3 stars
java-unit-test SKILL.md skill
baixuanzhu/skills · eval/java-unit-test/darwin-validation-v1.4.0/snapshots/versionB/SKILL.md · Java 单元测试**规范对齐**助手。在编写、评审、补全单元测试时使用本技能—— 无论用户是否提到具体框架(unit test / JUnit / Mockito / 测试用例 / 怎么测 / 测哪些 / 写多少测试)。…
v1.3.2 · audit A · 3 stars
java-unit-test SKILL.md skill
baixuanzhu/skills · eval/java-test/darwin-validation-v2.0.0/snapshots/blind/unit-B/versionA/SKILL.md · Java 开发期测试(纯单元测试)助手——@Mock + @InjectMocks,毫秒级,不起 Spring Context、不起容器、零测试基础设施。在编写、评审、补全、重构单元 测试时使用本技能,无论用户是否提到具体框架(unit…
v2.0.0 · audit A · 3 stars
java-unit-test SKILL.md skill
baixuanzhu/skills · eval/java-unit-test/darwin-validation-v1.4.0/snapshots/v1.3.2/SKILL.md · Java 单元测试**规范对齐**助手。在编写、评审、补全单元测试时使用本技能—— 无论用户是否提到具体框架(unit test / JUnit / Mockito / 测试用例 / 怎么测 / 测哪些 / 写多少测试)。…
v1.3.2 · audit A · 3 stars
java-unit-test SKILL.md skill
baixuanzhu/skills · eval/java-test/darwin-validation-v2.0.0/snapshots/v1-online-unit/SKILL.md · Java 单元测试助手。在编写、评审、补全、重构单元测试时使用本技能—— 无论用户是否提到具体框架(unit test / JUnit / Mockito / 测试用例 / 怎么测 / 测哪些 / 写多少)。 次级触发信号——代码或…
v1.5.3 · audit A · 3 stars
java-unit-test SKILL.md skill
baixuanzhu/skills · eval/java-test/darwin-validation-v2.0.0/snapshots/blind/unit-A/version2/SKILL.md · Java 开发期测试(纯单元测试)助手——@Mock + @InjectMocks,毫秒级,不起 Spring Context、不起容器、零测试基础设施。在编写、评审、补全、重构单元 测试时使用本技能,无论用户是否提到具体框架(unit…
v2.0.0 · audit A · 3 stars
java-unit-test SKILL.md skill
baixuanzhu/skills · eval/java-unit-test/darwin-validation-v1.4.0/snapshots/version1/SKILL.md · Java 单元测试**规范对齐**助手。在编写、评审、补全单元测试时使用本技能—— 无论用户是否提到具体框架(unit test / JUnit / Mockito / 测试用例 / 怎么测 / 测哪些 / 写多少测试)。…
v1.3.2 · audit A · 3 stars

Browse by kind, by grade A, or by owner.