{"id":"5997894d-f9b4-417b-a3c1-82c186db2912","shortId":"nJrr9h","kind":"skill","title":"131-java-testing-unit-testing","tagline":"Use when you need to review, improve, or write Java unit tests — including migrating from JUnit 4 to JUnit 5, adopting AssertJ for fluent assertions, structuring tests with Given-When-Then, ensuring test independence, applying parameterized tests, mocking dependencies with Mockit","description":"# Java Unit testing guidelines\n\nReview and improve Java unit tests using modern JUnit 5, AssertJ, and Mockito best practices.\n\n**What is covered in this Skill?**\n\n- JUnit 5 annotations: `@Test`, `@BeforeEach`, `@AfterEach`, `@DisplayName`, `@Nested`, `@ParameterizedTest`\n- AssertJ fluent assertions: `assertThat`, `assertThatThrownBy`\n- Given-When-Then test structure, descriptive test naming, single-responsibility tests\n- Test independence and isolated state\n- Parameterized tests: `@ValueSource`/`@CsvSource`/`@MethodSource`\n- Mockito dependency mocking: `@Mock`, `@InjectMocks`, `MockitoExtension`\n- Code coverage guidance (JaCoCo), package-private test visibility\n- Testing anti-patterns: reflection, shared state, hard-coded values, testing implementation details\n- Error handling: `assertThatThrownBy`, exception messages\n- JSpecify null-safety: `@NullMarked`, `@Nullable`\n- RIGHT-BICEP coverage principles, A-TRIP test quality, CORRECT boundary condition verification\n\n**Scope:** The reference is organized by examples (good/bad code patterns) for each core area. Apply recommendations based on applicable examples.\n\n## Constraints\n\nBefore applying any unit test changes, ensure the project compiles. If compilation fails, stop immediately — do not proceed until resolved. After applying improvements, run full verification.\n\n- **MANDATORY**: Run `./mvnw compile` or `mvn compile` before applying any change\n- **SAFETY**: If compilation fails, stop immediately and do not proceed — compilation failure is a blocking condition\n- **VERIFY**: Run `./mvnw clean verify` or `mvn clean verify` after applying improvements\n- **BEFORE APPLYING**: Read the reference for detailed examples, good/bad patterns, and constraints\n\n## When to use this skill\n\n- Review Java code for unit tests\n- Apply best practices for unit tests in Java code\n\n## Workflow\n\n1. **Compile project before unit-test changes**\n\nRun `./mvnw compile` or `mvn compile` and stop immediately if compilation fails.\n\n2. **Read unit-testing reference and evaluate coverage**\n\nRead `references/131-java-testing-unit-testing.md` and identify modernization and quality gaps in current tests.\n\n3. **Apply unit-testing best practices**\n\nImplement or refactor tests using JUnit 5, AssertJ, Mockito, parameterization, and stronger boundary checks.\n\n4. **Verify with full build**\n\nRun `./mvnw clean verify` or `mvn clean verify` after applying improvements.\n\n## Reference\n\nFor detailed guidance, examples, and constraints, see [references/131-java-testing-unit-testing.md](references/131-java-testing-unit-testing.md).","tags":["131","java","testing","unit","cursor","rules","jabrena","agent-skills","ai-skills","claude","claude-code","claude-code-skills"],"capabilities":["skill","source-jabrena","skill-131-java-testing-unit-testing","topic-agent-skills","topic-ai-skills","topic-claude","topic-claude-code","topic-claude-code-skills","topic-claude-code-subagents","topic-claude-skills","topic-cursor-agent","topic-cursor-ai","topic-cursor-skills","topic-cursorai","topic-github-copilot"],"categories":["cursor-rules-java"],"synonyms":[],"warnings":[],"endpointUrl":"https://skills.sh/jabrena/cursor-rules-java/131-java-testing-unit-testing","protocol":"skill","transport":"skills-sh","auth":{"type":"none","details":{"cli":"npx skills add jabrena/cursor-rules-java","source_repo":"https://github.com/jabrena/cursor-rules-java","install_from":"skills.sh"}},"qualityScore":"0.631","qualityRationale":"deterministic score 0.63 from registry signals: · indexed on github topic:agent-skills · 362 github stars · SKILL.md body (2,575 chars)","verified":false,"liveness":"unknown","lastLivenessCheck":null,"agentReviews":{"count":0,"score_avg":null,"cost_usd_avg":null,"success_rate":null,"latency_p50_ms":null,"narrative_summary":null,"summary_updated_at":null},"enrichmentModel":"deterministic:skill-github:v1","enrichmentVersion":1,"enrichedAt":"2026-04-26T12:53:35.144Z","embedding":null,"createdAt":"2026-04-18T22:02:00.252Z","updatedAt":"2026-04-26T12:53:35.144Z","lastSeenAt":"2026-04-26T12:53:35.144Z","tsv":"'/mvnw':214,241,293,351 '1':284 '131':1 '2':304 '3':324 '4':23,345 '5':26,62,75,337 'a-trip':156 'adopt':27 'aftereach':79 'annot':76 'anti':128 'anti-pattern':127 'appli':42,179,187,207,220,249,252,274,325,359 'applic':183 'area':178 'assert':31,85 'assertj':28,63,83,338 'assertthat':86 'assertthatthrownbi':87,142 'base':181 'beforeeach':78 'best':66,275,329 'bicep':153 'block':237 'boundari':162,343 'build':349 'chang':191,222,291 'check':344 'clean':242,246,352,356 'code':117,135,173,270,282 'compil':195,197,215,218,225,233,285,294,297,302 'condit':163,238 'constraint':185,262,367 'core':177 'correct':161 'cover':70 'coverag':118,154,312 'csvsourc':109 'current':322 'depend':46,112 'descript':94 'detail':139,257,363 'displaynam':80 'ensur':39,192 'error':140 'evalu':311 'exampl':171,184,258,365 'except':143 'fail':198,226,303 'failur':234 'fluent':30,84 'full':210,348 'gap':320 'given':36,89 'given-when-then':35,88 'good/bad':172,259 'guidanc':119,364 'guidelin':52 'handl':141 'hard':134 'hard-cod':133 'identifi':316 'immedi':200,228,300 'implement':138,331 'improv':13,55,208,250,360 'includ':19 'independ':41,102 'injectmock':115 'isol':104 'jacoco':120 'java':3,16,49,56,269,281 'java-testing-unit-test':2 'jspecifi':145 'junit':22,25,61,74,336 'mandatori':212 'messag':144 'methodsourc':110 'migrat':20 'mock':45,113,114 'mockit':48 'mockito':65,111,339 'mockitoextens':116 'modern':60,317 'mvn':217,245,296,355 'name':96 'need':10 'nest':81 'null':147 'null-safeti':146 'nullabl':150 'nullmark':149 'organ':169 'packag':122 'package-priv':121 'parameter':43,106,340 'parameterizedtest':82 'pattern':129,174,260 'practic':67,276,330 'principl':155 'privat':123 'proceed':203,232 'project':194,286 'qualiti':160,319 'read':253,305,313 'recommend':180 'refactor':333 'refer':167,255,309,361 'references/131-java-testing-unit-testing.md':314,369,370 'reflect':130 'resolv':205 'respons':99 'review':12,53,268 'right':152 'right-bicep':151 'run':209,213,240,292,350 'safeti':148,223 'scope':165 'see':368 'share':131 'singl':98 'single-respons':97 'skill':73,267 'skill-131-java-testing-unit-testing' 'source-jabrena' 'state':105,132 'stop':199,227,299 'stronger':342 'structur':32,93 'test':4,6,18,33,40,44,51,58,77,92,95,100,101,107,124,126,137,159,190,273,279,290,308,323,328,334 'topic-agent-skills' 'topic-ai-skills' 'topic-claude' 'topic-claude-code' 'topic-claude-code-skills' 'topic-claude-code-subagents' 'topic-claude-skills' 'topic-cursor-agent' 'topic-cursor-ai' 'topic-cursor-skills' 'topic-cursorai' 'topic-github-copilot' 'trip':158 'unit':5,17,50,57,189,272,278,289,307,327 'unit-test':288,306,326 'use':7,59,265,335 'valu':136 'valuesourc':108 'verif':164,211 'verifi':239,243,247,346,353,357 'visibl':125 'workflow':283 'write':15","prices":[{"id":"5e8dd619-9e15-4bbc-ba36-777f6d6987aa","listingId":"5997894d-f9b4-417b-a3c1-82c186db2912","amountUsd":"0","unit":"free","nativeCurrency":null,"nativeAmount":null,"chain":null,"payTo":null,"paymentMethod":"skill-free","isPrimary":true,"details":{"org":"jabrena","category":"cursor-rules-java","install_from":"skills.sh"},"createdAt":"2026-04-18T22:02:00.252Z"}],"sources":[{"listingId":"5997894d-f9b4-417b-a3c1-82c186db2912","source":"github","sourceId":"jabrena/cursor-rules-java/131-java-testing-unit-testing","sourceUrl":"https://github.com/jabrena/cursor-rules-java/tree/main/skills/131-java-testing-unit-testing","isPrimary":false,"firstSeenAt":"2026-04-18T22:02:00.252Z","lastSeenAt":"2026-04-26T12:53:35.144Z"}],"details":{"listingId":"5997894d-f9b4-417b-a3c1-82c186db2912","quickStartSnippet":null,"exampleRequest":null,"exampleResponse":null,"schema":null,"openapiUrl":null,"agentsTxtUrl":null,"citations":[],"useCases":[],"bestFor":[],"notFor":[],"kindDetails":{"org":"jabrena","slug":"131-java-testing-unit-testing","github":{"repo":"jabrena/cursor-rules-java","stars":362,"topics":["agent-skills","ai-skills","claude","claude-code","claude-code-skills","claude-code-subagents","claude-skills","cursor-agent","cursor-ai","cursor-skills","cursorai","github-copilot","intellij-idea","java","prompting","system-prompts"],"license":"apache-2.0","html_url":"https://github.com/jabrena/cursor-rules-java","pushed_at":"2026-04-26T12:50:01Z","description":"A curated and opinionated collection of Skills and Agents to be used in modern SDLC workflows for Java Enterprise development with your favorite AI Agent harness.","skill_md_sha":"6662c3913f52f6b6c53455665d22a5563b762887","skill_md_path":"skills/131-java-testing-unit-testing/SKILL.md","default_branch":"main","skill_tree_url":"https://github.com/jabrena/cursor-rules-java/tree/main/skills/131-java-testing-unit-testing"},"layout":"multi","source":"github","category":"cursor-rules-java","frontmatter":{"name":"131-java-testing-unit-testing","license":"Apache-2.0","description":"Use when you need to review, improve, or write Java unit tests — including migrating from JUnit 4 to JUnit 5, adopting AssertJ for fluent assertions, structuring tests with Given-When-Then, ensuring test independence, applying parameterized tests, mocking dependencies with Mockito, verifying boundary conditions (RIGHT-BICEP, CORRECT, A-TRIP), leveraging JSpecify null-safety annotations, or eliminating testing anti-patterns such as reflection-based tests or shared mutable state. This should trigger for requests such as Review Java code for unit tests; Apply best practices for unit tests in Java code. Part of cursor-rules-java project"},"skills_sh_url":"https://skills.sh/jabrena/cursor-rules-java/131-java-testing-unit-testing"},"updatedAt":"2026-04-26T12:53:35.144Z"}}