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.
mdr add baixuanzhu/skills/java-unit-test@v2.2.0Pins 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
mdr add baixuanzhu/skills/java-unit-test@sha256:0909dee51cb5f4a1The 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.
[](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.
| version | committed | commit | size | audit | |
|---|---|---|---|---|---|
| v2.2.0 latest | 2026-10-24 | 95aa2f2 | 7,156 B | A | view · diff |
| v2.1.1 | 2026-10-24 | d3663e1 | 7,480 B | A | view · diff |
| v2.1.0 | 2026-10-24 | 9d5c0e9 | 7,609 B | A | view · diff |
| v2.0.0 | 2026-10-04 | b24ce00 | 11,889 B | A | view · diff |
| v2.0.0 | 2026-10-04 | 13088df | 11,833 B | A | view |
Audit of the latest version
- 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
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
Every file in baixuanzhu/skills