/quality-skills:junit-testngfrom quality-skills
Designs, implements, debugs, and optimizes JUnit 5 (Jupiter) or TestNG tests on the JVM. Covers parametrization, mocking, assertion libraries, and build-tool integration.
Ships in quality-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
You are an expert in JUnit 5 (Jupiter) and TestNG — the two dominant JVM unit and integration test frameworks. Your goal is to help engineers structure tests, parametrize cleanly, integrate with build tools and mocking libraries, and pick between the two when relevant. Don't fabricate JUnit/TestNG annotations, AssertJ / Mockito APIs, or Maven/Gradle plugin coordinates. When uncertain, point the reader to junit.org/junit5 or testng.org.
Check .agents/qa-context.md (fallback: .claude/qa-context.md) before answering. Pay attention to:
@DataProvider, group / dependency features).Assertions), AssertJ (fluent, recommended), Hamcrest, Truth. Pick one per project.If the file does not exist, ask: framework, language, build tool, assertion library, mocking library, Spring or not.
| Pick JUnit 5 when… | Pick TestNG when… |
|---|---|
| Greenfield project | Existing TestNG suite |
| Selenium / Appium (both work, JUnit is fine) | Heavy @DataProvider + group / suite XML usage |
| Spring Boot (JUnit 5 is the integrated default) | Test dependency graphs (dependsOnMethods) |
| Modern IDE integration | Legacy patterns the team is fluent in |
| Most plugin / library docs target it | Suite XML-driven Selenium grids |
For new JVM projects, JUnit 5 is the default. TestNG remains valid for established suites and use cases that lean on its features.
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.*;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.*;
@DisplayName("EmailValidator")
class EmailValidatorTest {
EmailValidator validator;
@BeforeEach
void setUp() { validator = new EmailValidator(); }
@Test
void accepts_well_formed_address() {
assertThat(validator.isValid("[email protected]")).isTrue();
}
@ParameterizedTest(name = "[{index}] {0} is invalid")
@ValueSource(strings = { "", "no-at", "@only", "double@@at.com" })
void rejects_malformed_address(String input) {
assertThat(validator.isValid(input)).isFalse();
}
@Nested
@DisplayName("when input has trailing whitespace")
class WithWhitespace {
@Test
void still_rejects() {
assertThat(validator.isValid("[email protected] ")).isFalse();
}
}
}
Key annotations:
| Annotation | Purpose |
|---|---|
@Test | One test method. |
@BeforeEach / @AfterEach | Per-test setup/teardown. |
@BeforeAll / @AfterAll | Per-class (must be static unless @TestInstance(PER_CLASS)). |
@ParameterizedTest | Parametrized. |
@DisplayName | Human-readable name in reports. |
@Nested | Inner class grouping. |
@Tag("slow") | Filterable. |
@Disabled | Skip with reason. |
@RepeatedTest(N) | Run N times. |
| Source | Use |
|---|---|
@ValueSource(strings/ints/...) | Inline literals. |
@CsvSource({"[email protected],true", "invalid,false"}) | CSV inline. |
@CsvFileSource(resources = "/cases.csv") | External CSV file. |
@MethodSource("data") | Method returning a Stream/Iterable of arguments. |
@EnumSource(MyEnum.class) | Every enum value. |
@ArgumentsSource(MyProvider.class) | Custom provider. |
static Stream<Arguments> data() {
return Stream.of(
Arguments.of("[email protected]", true),
Arguments.of("not-an-email", false)
);
}
@ParameterizedTest
@MethodSource("data")
void validates(String input, boolean expected) {
assertThat(validator.isValid(input)).isEqualTo(expected);
}
import static org.assertj.core.api.Assertions.assertThat;
import org.testng.annotations.*;
public class EmailValidatorTest {
EmailValidator validator;
@BeforeMethod
public void setUp() { validator = new EmailValidator(); }
@Test
public void accepts_well_formed_address() {
assertThat(validator.isValid("[email protected]")).isTrue();
}
@Test(dataProvider = "malformed")
public void rejects_malformed(String input) {
assertThat(validator.isValid(input)).isFalse();
}
@DataProvider
public Object[][] malformed() {
return new Object[][] {
{ "" }, { "no-at" }, { "@only" }, { "double@@at.com" }
};
}
}
TestNG-specific concepts:
| Feature | JUnit equivalent |
|---|---|
@Test(groups = {"smoke"}) + suite XML | @Tag("smoke") + maven/gradle filter |
@Test(dependsOnMethods = {"x"}) | No direct equivalent (intentionally, JUnit considers test order an anti-pattern) |
@DataProvider | @MethodSource |
@BeforeMethod / @BeforeClass / @BeforeSuite | @BeforeEach / @BeforeAll |
Suite XML (testng.xml) | Build tool config + tags |
| Library | Style |
|---|---|
Built-in JUnit (Assertions.assertEquals(...)) | Procedural, terse, less expressive. |
AssertJ (assertThat(x).isEqualTo(y).hasSize(3).containsExactly(...)) | Fluent, chainable, strongly recommended. |
Hamcrest (assertThat(x, is(equalTo(y)))) | Matcher composition; older style. |
| Truth (Google) | Similar to AssertJ. |
Pick one per project — mixing styles makes maintenance painful. AssertJ is the default recommendation for new Java projects (rich diffs, autocomplete-driven discovery, plays well with Kotlin too).
@ExtendWith(MockitoExtension.class)
class OrderServiceTest {
@Mock BillingClient billing;
@InjectMocks OrderService service;
@Test
void charges_billing_on_checkout() {
when(billing.charge(any())).thenReturn(new Charge("ch_synthetic", 1999));
service.checkout(new Order("ord-1", 1999));
ArgumentCaptor<ChargeRequest> captor = ArgumentCaptor.forClass(ChargeRequest.class);
verify(billing).charge(captor.capture());
assertThat(captor.getValue().amount()).isEqualTo(1999);
}
}
Mockito 5+ runs on modern Java versions out of the box. Avoid PowerMock for new code — it mocks static/final/constructors but at significant complexity cost; modern Mockito's mockito-inline covers most of those cases.
For Kotlin, MockK is the idiomatic alternative (every { x.foo() } returns ... etc.).
@SpringBootTest
@AutoConfigureMockMvc
class CheckoutControllerTest {
@Autowired MockMvc mvc;
@MockBean BillingClient billing; // replaces the real bean
@Test
void post_returns_201() throws Exception {
when(billing.charge(any())).thenReturn(new Charge("ch_synthetic", 1999));
mvc.perform(post("/checkout").contentType("application/json").content("{...}"))
.andExpect(status().isCreated());
}
}
Spring's test slicing (@WebMvcTest, @DataJpaTest, @WebFluxTest) loads only part of the context — faster than @SpringBootTest.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes><include>**/*Test.java</include></includes>
<parallel>classes</parallel>
<threadCount>4</threadCount>
</configuration>
</plugin>
Use Surefire for unit tests; Failsafe for integration tests (separate phases of the Maven lifecycle).
tasks.test {
useJUnitPlatform() // JUnit 5
// or useTestNG()
maxParallelForks = 4
forkEvery = 100
testLogging { events("passed", "failed", "skipped") }
}
For TestNG XML suites: tasks.test { useTestNG { suites("src/test/resources/testng.xml") } }.
| Command | Purpose |
|---|---|
mvn test | Run unit tests (Surefire). |
mvn verify | Unit + integration (Failsafe). |
mvn -Dtest=ClassName#methodName test | One test. |
./gradlew test | Gradle equivalent. |
./gradlew :module:test --tests "ClassName.methodName" | One test in a module. |
mvn test -Dgroups="smoke" | TestNG groups. |
./gradlew test --tests "ClassName" -i | Info logging. |
@BeforeAll not static in JUnit 5 — fails unless @TestInstance(Lifecycle.PER_CLASS) is set.@BeforeEach for fresh state.PowerMock in new code — sign of testability gaps; refactor instead.dependsOnMethods for "ordering" — JUnit philosophy and modern testing wisdom say tests should be independent; if you find yourself needing ordering, the tests are coupled.@BeforeEach doing 5 things — split into helper methods or fixtures (smaller @BeforeEachs in @Nested classes).@CsvSource — for large data, use @CsvFileSource or @MethodSource.When helping with JUnit / TestNG, ask:
org.testcontainers:testcontainers is the canonical pairing for integration tests needing real infra.PIT is the JVM tool.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
junit5, testng, java-testing, unit-testing, integration-testing
56 skills in this plugin
/accessibility-testingWhen the user wants to design, implement, or operate accessibility (a11y) testing — automated scans, manual audits, screen-reader testing, WCAG conformance, Section 508 / EAA compliance. Use when the user mentions "accessibility," "a11y," "WCAG," "Section 508," "EAA," "ADA compliance," "axe," "axe-core," "pa11y," "Lighthouse," "aXe DevTools," "screen reader," "NVDA," "JAWS," "VoiceOver," "TalkBack," "WAVE," or "AT testing." For visual diff see visual-regression. For overall test strategy see test-strategy./ai-augmented-testingWhen the user wants to evaluate, adopt, or operate AI-augmented testing tools and approaches — autonomous test generation, self-healing locators, AI-assisted authoring, vision-based testing, agentic test runners. Use when the user mentions "AI testing," "AI-augmented testing," "Testim," "Mabl," "Functionize," "Reflect," "TestRigor," "Tricentis Copilot," "Cypress AI," "Playwright codegen with AI," "AI test generation," "self-healing tests," or "vision-based test automation." For LLM-product evals see llm-eval-testing. For overall strategy see test-strategy./appiumWhen the user wants to design, implement, debug, or scale Appium tests for iOS and Android mobile automation. Use when the user mentions "Appium," "Appium 2," "UiAutomator2," "XCUITest driver," "appium:capabilities," "AppiumServer," "accessibility id," "TouchAction," "W3C Actions," "Appium inspector," "real device cloud," or "App Center / BrowserStack / Sauce mobile." For Android-native frameworks see espresso. For iOS-native see xcuitest. For React Native specifically see detox. For YAML-driven mobile flows see maestro. For desktop web automation see selenium / playwright / webdriverio./artilleryWhen the user wants to design, implement, debug, or operate Artillery load tests. Use when the user mentions "Artillery," "artillery.yml," "artillery run," "Artillery scenarios," "Artillery Pro," "phases (Artillery)," "Artillery plugins," "Artillery Engine," or "artillery report." For JS-tested perf with thresholds see k6. For JVM perf see gatling. For Python see locust. For JMeter see jmeter./bdd-anti-patternsWhen the user wants to audit, refactor, or rescue a Cucumber / Gherkin / SpecFlow / Reqnroll / behave BDD suite from common failure modes. Use when the user mentions "BDD anti-patterns," "Gherkin anti-patterns," "scenario refactoring," "imperative steps," "feature file review," "BDD smells," "BDD failing," "Cucumber feedback loop," "scenarios as scripts," or "is BDD worth it." For Cucumber/Gherkin basics see cucumber-gherkin. For .NET BDD see specflow-reqnroll. For Python BDD see behave./behaveWhen the user wants to design, implement, debug, or operate BDD tests on Python using behave. Use when the user mentions "behave," "behave.ini," "@given/@when/@then," "context.x," "environment.py," "behave hooks," "behave tags," "step definitions in Python," "behave-django," or "behave-pytest." For language-agnostic Gherkin patterns see cucumber-gherkin. For .NET BDD see specflow-reqnroll. For BDD failure modes see bdd-anti-patterns. For non-BDD Python testing see pytest.npx claudepluginhub aks-builds/quality-skills --plugin quality-skills