.cursor/skills/qa-junit5-writer/SKILL.md
Generate JUnit 5 unit and integration tests for Java with parameterized tests, nested classes, extensions, Mockito mocking, and AssertJ assertions.
npx skillsauth add AZANIR/qa-skills qa-junit5-writerInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Write JUnit 5 unit and integration tests from test case specifications. Transform structured test cases into executable JUnit 5 test classes with parameterized tests, nested classes for organization, extensions, Mockito mocking, and AssertJ assertions.
| Feature | Description | | ------- | ----------- | | @Test | Standard test methods | | @ParameterizedTest | Data-driven tests with @CsvSource, @MethodSource, @EnumSource | | @Nested | Logical grouping; inner classes with @BeforeEach per level | | @ExtendWith | Extensions (MockitoExtension, custom) | | Mockito | @Mock, @InjectMocks, when().thenReturn(), verify() | | AssertJ | Fluent assertions: assertThat().isEqualTo(), containsExactly() | | @TestInstance | PER_CLASS for shared setup; PER_METHOD default | | @Tag | Categorization for selective execution | | @DisplayName | Human-readable test names |
{Class}Test.java with appropriate structuremvn test or ./gradlew test| Pattern | Usage |
| ------- | ----- |
| @Test | JUnit 5 test method |
| @ParameterizedTest | Data-driven test |
| @CsvSource({"a,1", "b,2"}) | Inline CSV data |
| @MethodSource("provideData") | Method-provided data |
| @Nested | Group related tests |
| @ExtendWith(MockitoExtension.class) | Enable Mockito |
| @Mock | Mock dependency |
| @InjectMocks | Inject mocks into SUT |
| when(mock.method()).thenReturn(value) | Stub mock |
| verify(mock, times(1)).method() | Verify interaction |
| assertThat(actual).isEqualTo(expected) | AssertJ assertion |
@ParameterizedTest
@CsvSource({"admin, true", "user, false"})
void shouldCheckAccess(String role, boolean expected) {
assertThat(service.hasAccess(role)).isEqualTo(expected);
}
@ParameterizedTest
@MethodSource("provideInvalidInputs")
void shouldRejectInvalidInput(String input) {
assertThatThrownBy(() -> validator.validate(input))
.isInstanceOf(ValidationException.class);
}
Use @Nested for logical grouping; each nested class gets its own @BeforeEach:
@DisplayName("UserService")
class UserServiceTest {
@Nested
@DisplayName("when user exists")
class WhenUserExists {
@Test
void shouldReturnUser() { ... }
}
@Nested
@DisplayName("when user not found")
class WhenUserNotFound {
@Test
void shouldThrowException() { ... }
}
}
{Class}Test.java — Test classes (e.g., UserServiceTest.java, OrderValidatorTest.java)src/test/java mirroring production package structureCan do (autonomous):
Cannot do (requires confirmation):
Will not do (out of scope):
mvn test)references/patterns.md — Parameterized, nested, extensions, lifecyclereferences/assertions.md — AssertJ assertion referencereferences/config.md — Maven/Gradle JUnit 5 config, Surefire plugin{Class}Test.java convention| Symptom | Likely Cause | Fix |
| ------- | ------------ | --- |
| Mock not injected | Wrong extension or order | Use @ExtendWith(MockitoExtension.class); @InjectMocks before @Mock |
| ParameterizedTest fails | Invalid CSV/method source | Check @CsvSource format; ensure @MethodSource returns Stream |
| Nested @BeforeEach runs twice | Misunderstanding lifecycle | Each @Nested level has own lifecycle; @BeforeEach runs per test in that level |
| AssertJ import error | Wrong static import | Use import static org.assertj.core.api.Assertions.assertThat |
| Test order dependent | Shared state | Ensure test isolation; use @TestInstance(PER_METHOD) or fresh fixtures |
| Surefire skips tests | JUnit 4 engine conflict | Exclude junit-vintage; use junit-platform-surefire-provider |
tools
Analyze OpenAPI/Swagger spec (JSON or YAML) against existing test files and generate an HTML coverage report with QA automation tasks. Use when user provides an OpenAPI spec file and wants to know test coverage status.
testing
Universal QA plan generator supporting 10 plan types including test plans, sprint plans, regression plans, release plans, UAT plans, performance plans, migration plans, onboarding plans, and custom plans.
development
Generate consumer-driven contract tests using Pact for JavaScript and Python to verify microservice API compatibility between consumer and provider.
development
Master skill coordinating all QA skills through pipeline modes (full-cycle, docs-only, testcases-only, write-tests, report), formalized handoff chains, scheduler rules, and framework/language selection based on project context.