
This covers JUnit 5 fundamentals through advanced parameterized testing patterns. It's solid for teams standardizing on testing conventions or developers moving from JUnit 4 who need the new annotation syntax and parameterized test approaches. The guidance on @ParameterizedTest with @ValueSource, @CsvSource, and @MethodSource is thorough, plus it includes practical setup for Maven/Gradle dependencies. The test naming conventions and AAA pattern recommendations will help maintain readable test suites. One limitation: it focuses heavily on unit testing mechanics but doesn't dive into integration testing strategies or more complex mocking scenarios beyond basic Mockito usage.
$ npx -y skills add github/awesome-copilot --skill java-junit --agent claude-codeInstalls into .claude/skills of the current project.
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.
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.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.java-upgrade if installed).| 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).
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.
assertNotNull.AssertionError/Exception to make a test pass.String, or the class under test; use real instances or simple fakes.@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-core as a -javaagent instead (setup for Maven and Gradle in references/assertj-and-mockito.md, verified on JDK 21 and 25). Check the resolved version first: earlier 5.x jars lack Premain-Class and cannot be used as the agent. Ask before upgrading; otherwise use the instrumentation setup documented for the installed version.mockStatic/mockConstruction; wrap the static call behind an interface.java.time.Clock (Clock.fixed(...)) and call Instant.now(clock); avoid Instant.now()/LocalDate.now() in code under test.Random/RandomGenerator with a fixed seed; log the seed if generated.Unit (*Test) | Integration (*IT) | |
|---|---|---|
| Maven | Surefire, mvn test | Failsafe, mvn verify |
| Gradle | test task | separate integrationTest task (JVM Test Suite) wired into check |
| Speed | milliseconds, no I/O | may use Docker/DB |
Surefire defaults pick *Test, Test*, *Tests, *TestCase; Failsafe picks *IT, IT*, *ITCase. Failsafe needs the integration-test and verify goals bound and is run by mvn verify, not mvn test. Alternatively split by @Tag. For databases and brokers see java-testcontainers; for Spring slices see spring-boot-testing. Full build snippets: references/build-setup.md.
<argLine>@{argLine} ...</argLine> so the JaCoCo agent is not overwritten.references/build-setup.md, which records a verified pitest-maven + JUnit 5 plugin run).@Disabled, weaken (looser assertion, wider tolerance, swallowed exception) or skip a failing test to get green. Find the cause.-DskipTests, -Dmaven.test.skip, -x test or failIfNoTests=false to make a build pass.mvn -q -Dtest=OrdersTest test (one method: -Dtest='OrdersTest#place_should_saveAndNotify_when_itemValid'), then mvn verify../gradlew test --tests 'demo.OrdersTest', then ./gradlew check.
Prefer the project wrapper (./mvnw, ./gradlew) when present.references/assertj-and-mockito.md: AssertJ patterns, Mockito strictness/captors/agent setup, when not to mock.references/build-setup.md: Maven and Gradle (Kotlin DSL) setups for JUnit 5/6, Failsafe split, JaCoCo, PIT.Sponsors