java-junit

Solid

Get best practices for JUnit 5 unit testing, including data-driven tests

AI & Automation 34,233 stars 4188 forks Updated today MIT

Install

View on GitHub

Quality Score: 93/100

Stars 20%
100
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# 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`, and `junit-jupiter-params` for parameterized tests. - Use build tool commands to run tests: `mvn test` or `gradle test`. ## Test Structure - Test classes should have a `Test` suffix, e.g., `CalculatorTest` for a `Calculator` class. - Use `@Test` for test methods. - Follow the Arrange-Act-Assert (AAA) pattern. - Name tests using a descriptive convention, like `methodName_should_expectedBehavior_when_scenario`. - Use `@BeforeEach` and `@AfterEach` for per-test setup and teardown. - Use `@BeforeAll` and `@AfterAll` for per-class setup and teardown (must be static methods). - Use `@DisplayName` to 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 `@ParameterizedTest` to mark a method as a parameterized test. - Use `@ValueSource` for simple literal values (strings, ints, etc.). - Use `@MethodSource` to refer to a factory method that provides test arguments as a `Stream`, `Collectio...

Details

Author
github
Repository
github/awesome-copilot
Created
11 months ago
Last Updated
today
Language
Python
License
MIT

Similar Skills

Semantically similar based on skill content — not just same category