junit5-testing
Skill8 starsChanged 26 days agoMITView on GitHub
Get best practices for JUnit 5 unit testing, including data-driven tests
In this repository99 other files it gives its agents.
- skills/react-hook-form-patterns/AGENTS.mdAGENTS.md
- skills/zod-schema-validation/AGENTS.mdAGENTS.md
- Add Admin API EndpointSkill
- add-malli-schemasSkill
- add-uint-supportSkill
- analytics-eventsSkill
- analyze-ciSkill
- asyncio-patternsSkill
- axum-web-patternsSkill
- bash-defensive-patternsSkill
- bats-shell-testingSkill
- bazel-build-optimizationSkill
- beautifulsoup-parsingSkill
- changelog-automationSkill
- cheerio-parsingSkill
- clap-cli-patternsSkill
- clojure-writeSkill
- cobra-cli-developmentSkill
- creating-financial-modelsSkill
- dbt-transformation-patternsSkill
- distributed-tracingSkill
- django-patternsSkill
- drizzle-orm-patternsSkill
- fastapi-patternsSkill
- fastify-patternsSkill
- fixSkill
- github-actions-templatesSkill
- gitlab-ci-patternsSkill
- gitops-workflowSkill
- go-cache-hotSkill
- go-concurrency-patternsSkill
- go-errors-oopsSkill
- go-fx-diSkill
- go-monads-moSkill
- go-swagger-codegenSkill
- go-testify-patternsSkill
- grafana-dashboardsSkill
- graphql-schema-designSkill
- grpc-service-definitionSkill
- hono-patternsSkill
- implementing-agent-modesSkill
- implementing-jsc-classes-zigSkill
- istio-traffic-managementSkill
- jest-advanced-patternsSkill
- k8s-manifest-generatorSkill
- kysely-query-builderSkill
- langsmith-fetchSkill
- linkerd-patternsSkill
- llm-evaluationSkill
- mcp-builderSkill
- mypy-type-checkingSkill
- networkx-graph-algorithmsSkill
- nx-workspace-patternsSkill
- pandas-dataframe-patternsSkill
- pillow-image-processingSkill
- polars-dataframeSkill
- prisma-schema-patternsSkill
- prometheus-configurationSkill
- prompt-engineering-patternsSkill
- pydicom-dicom-parsingSkill
- The first 60 shown.
The file
Show its rules and text
We split this skill into the rules it gives an agent
27 rules. About 0 are common, 7 are distinctive, and 20 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈7
Distinctive · estimate
This author's own choices. Worth a look.
20
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 12
Use a standard Maven or Gradle project structure.
- Very specific: line 13
Place test source code in src/test/java.
- Very specific: line 15
Use build tool commands to run tests: mvn test or gradle test.
- Very specific: line 19
Test classes should have a Test suffix, e.g., CalculatorTest for a Calculator class.
- Very specific: line 20
Use @Test for test methods.
- Distinctive: line 21
Follow the Arrange-Act-Assert (AAA) pattern.
- Very specific: line 23
Use @BeforeEach and @AfterEach for per-test setup and teardown.
- Very specific: line 24
Use @BeforeAll and @AfterAll for per-class setup and teardown (must be static methods).
- Very specific: line 25
Use @DisplayName to provide a human-readable name for test classes and methods.
- Distinctive: line 29
Keep tests focused on a single behavior.
- Distinctive: line 30
Avoid testing multiple conditions in one test method.
- Very specific: line 36
Use @ParameterizedTest to mark a method as a parameterized test.
- Very specific: line 37
Use @ValueSource for simple literal values (strings, ints, etc.).
- Very specific: line 38
Use @MethodSource to refer to a factory method that provides test arguments as a Stream, Collection, etc.
- Very specific: line 39
Use @CsvSource for inline comma-separated values.
- Very specific: line 40
Use @CsvFileSource to use a CSV file from the classpath.
- Very specific: line 41
Use @EnumSource to use enum constants.
- Very specific: line 45
Use the static methods from org.junit.jupiter.api.Assertions (e.g., assertEquals, assertTrue, assertNotNull).
- Very specific: line 47
Use assertThrows or assertDoesNotThrow to test for exceptions.
- Distinctive: line 49
Use descriptive messages in assertions to provide clarity on failure.
- Distinctive: line 53
Use a mocking framework like Mockito to create mock objects for dependencies.
- Very specific: line 54
Use @Mock and @InjectMocks annotations from Mockito to simplify mock creation and injection.
- Distinctive: line 55
Use interfaces to facilitate mocking.
- Very specific: line 60
Use @Tag to categorize tests (e.g., @Tag("fast"), @Tag("integration")).
- Very specific: line 61
Use @TestMethodOrder(MethodOrderer.OrderAnnotation.class) and @Order to control test execution order when strictly necessary.
- Very specific: line 62
Use @Disabled to temporarily skip a test method or class, providing a reason.
- Very specific: line 63
Use @Nested to group tests in a nested inner class for better organization and structure.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
JUnit 5+ Best Practices
Your goal is to help me write effective unit tests with JUnit 5, covering both standard and data-driven testing approaches.
Project Setup
- Use a standard Maven or Gradle project structure.
- Place test source code in
src/test/java. - Include dependencies for
junit-jupiter-api,junit-jupiter-engine, andjunit-jupiter-paramsfor parameterized tests. - Use build tool commands to run tests:
mvn testorgradle test.
Test Structure
- Test classes should have a
Testsuffix, e.g.,CalculatorTestfor aCalculatorclass. - Use
@Testfor test methods. - Follow the Arrange-Act-Assert (AAA) pattern.
- Name tests using a descriptive convention, like
methodName_should_expectedBehavior_when_scenario. - Use
@BeforeEachand@AfterEachfor per-test setup and teardown. - Use
@BeforeAlland@AfterAllfor per-class setup and teardown (must be static methods). - Use
@DisplayNameto provide a human-readable name for test classes and methods.
Standard Tests
- Keep tests focused on a single behavior.
- Avoid testing multiple conditions in one test method.
- Make tests independent and idempotent (can run in any order).
- Avoid test interdependencies.
Data-Driven (Parameterized) Tests
- Use
@ParameterizedTestto mark a method as a parameterized test. - Use
@ValueSourcefor simple literal values (strings, ints, etc.). - Use
@MethodSourceto refer to a factory method that provides test arguments as aStream,Collection, etc. - Use
@CsvSourcefor inline comma-separated values. - Use
@CsvFileSourceto use a CSV file from the classpath. - Use
@EnumSourceto use enum constants.
Assertions
- Use the static methods from
org.junit.jupiter.api.Assertions(e.g.,assertEquals,assertTrue,assertNotNull). - For more fluent and readable assertions, consider using a library like AssertJ (
assertThat(...).is...). - Use
assertThrowsorassertDoesNotThrowto test for exceptions. - Group related assertions with
assertAllto ensure all assertions are checked before the test fails. - Use descriptive messages in assertions to provide clarity on failure.
Mocking and Isolation
- Use a mocking framework like Mockito to create mock objects for dependencies.
- Use
@Mockand@InjectMocksannotations from Mockito to simplify mock creation and injection. - Use interfaces to facilitate mocking.
Test Organization
- Group tests by feature or component using packages.
- Use
@Tagto categorize tests (e.g.,@Tag("fast"),@Tag("integration")). - Use
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)and@Orderto control test execution order when strictly necessary. - Use
@Disabledto temporarily skip a test method or class, providing a reason. - Use
@Nestedto group tests in a nested inner class for better organization and structure.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

