java-junit
БесплатноБез исполняемых скриптовНе проверенJUnit 5 testing patterns and parameterized-test guidance. Use when writing or reviewing Java unit tests.
от PracticalSwan★ 25 звёзд на GitHubОб этом скилле
Java Testing with JUnit 5/6, AssertJ and Mockito
Framework-neutral guidance for fast, deterministic unit tests. For Spring slices use spring-boot-testing (if installed); for real databases/brokers in Docker use java-testcontainers; for failures you cannot explain, java-debugging.
First: detect, don't impose
- Read
pom.xml/build.gradle*: JUnit version (junit-jupiter,junit-bom, or inherited from a Spring Boot BOM), assertion library, Mockito, Surefire/Failsafe versions, Java release. - Copy the conventions already in
src/test/java(naming, assertion library, static imports, mocking style). Do not introduce AssertJ, Mockito or JaCoCo into a project that lacks them without asking. - Never bump the JUnit major version implicitly; upgrading is its own task (see
java-upgradeif installed).
JUnit 5 vs JUnit 6
| JUnit 5 (last 5.14.x) | JUnit 6 (6.0 released; 6.1.x current) | |
|---|---|---|
| Java baseline | 8 | 17 (verified in the published Gradle module metadata) |
| Versioning | Platform 1.x, Jupiter 5.x, Vintage 5.x | One version number for Platform, Jupiter and Vintage |
| API | org.junit.jupiter.api.* |
Same packages; the Jupiter tests in this skill compile and pass unchanged on 5.14.4 and 6.0.3 |
| Removed in 6.0 | MethodOrderer.Alphanumeric, the deprecated two-argument InvocationInterceptor.interceptDynamicTest(Invocation, ExtensionContext) overload (the three-argument one remains), junit.jupiter.tempdir.scope, @CsvFileSource(lineSeparator) |
|
| CSV | univocity-parsers | FastCSV: stricter parsing (no characters after a closing quote); header-field options now apply to headers |
| Other | junit-jupiter-migrationsupport deprecated; invalid enum-style config values now fail discovery; @Nested class order deterministic but non-obvious |
Source: JUnit 6.0.0 release notes (https://docs.junit.org/6.0.0/release-notes.html). Read the notes for the target version (https://docs.junit.org/current/release-notes/) and prefer them over this table. JUnit 4 tests need the Vintage engine; do not mix org.junit.Test and org.junit.jupiter.api.Test in one class.
Dependencies (same for 5 and 6; verified with Maven and Gradle): import org.junit:junit-bom, then declare org.junit.jupiter:junit-jupiter (aggregates api, params, engine) with test scope. Gradle 9 additionally requires testRuntimeOnly("org.junit.platform:junit-platform-launcher") (verified: without it the test executor fails with "Failed to load JUnit Platform") and tasks.test { useJUnitPlatform() }. Maven needs Surefire 3.x (verified with 3.6.0).
Assertions
Match the project's library. Plain Jupiter rules: expected value first, lazy Supplier messages, assertAll, assertThrowsExactly, timeouts. (The separate instructions/java-junit5-assertions.instructions.md resource has the longer version but is not installed with this skill.) If the project uses AssertJ, prefer it for collections, strings and exceptions; patterns (soft assertions, assertThatThrownBy, extracting, containsExactly, usingRecursiveComparison) are in references/assertj-and-mockito.md.
- Assert on outcomes and state, not on how many times internals were called.
- Compare values; avoid bare
assertNotNull. - Never catch
AssertionError/Exceptionto make a test pass.
Mocking (Mockito)
- Mock collaborators across a boundary (repository, HTTP client, clock, message sender). Do not mock value objects, records, collections,
String, or the class under test; use real instances or simple fakes. - Prefer a hand-written fake over a mock when the interaction is stateful.
- Use
@ExtendWith(MockitoExtension.class)with@Mock/@InjectMocks/@Captor. Strict stubs are the default there, so an unused stub fails the test (UnnecessaryStubbingException). Fix the test; relax with@MockitoSettings(strictness = Strictness.LENIENT)only for a justified shared setup. - Mockito 5 uses the inline mock maker by default. On JDK 21+ it may self-attach and print a dynamic-agent warning. With Mockito 5.14.0+, register
mockito-coreas a-javaagentinstead (setup for Maven and Gradle inreferences/assertj-and-mockito.md, verified on JDK 21 and 25). Check the resolved version first: earlier 5.x jars lackPremain-Classand cannot be used as the agent. Ask before upgrading; otherwise use the instrumentation setup documented for the installed version. - Mockito 5 requires Java 11+. Its default inline mock maker does not work on GraalVM native image, where the subclass mock maker is appropriate (Mockito 5.0.0 release notes, https://github.com/mockito/mockito/releases/tag/v5.0.0).
- Avoid
mockStatic/mockConstruction; wrap the static call behind an interface.
Determinism
- Time: inject
java.time.Clock(Clock.fixed(...)) and callInstant.now(clock); avoidInstant.now()/LocalDate.now()in code under test. - Randomness: inject a
Random/RandomGeneratorwith a fixed seed; log the see
Установить java-junit в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл java-junit?
JUnit 5 testing patterns and parameterized-test guidance. Use when writing or reviewing Java unit tests.
Как установить скилл java-junit?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл java-junit запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic