java-junit
Installation
Summary
JUnit 5 best practices for standard and data-driven unit testing with practical patterns.
- Covers test structure using Arrange-Act-Assert pattern, lifecycle annotations (
@BeforeEach,@AfterEach,@BeforeAll,@AfterAll), and naming conventions with@DisplayName - Parameterized testing via
@ParameterizedTestwith multiple sources:@ValueSource,@MethodSource,@CsvSource,@CsvFileSource, and@EnumSource - Assertion strategies including static
Assertionsmethods, AssertJ fluent syntax, exception testing withassertThrows, and grouped assertions viaassertAll - Test organization with packages,
@Tagfor categorization,@Nestedfor grouping, and Mockito integration for dependency isolation
SKILL.md
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).