java-junit

Guides writing JUnit 5 unit tests including parameterized and data-driven test patterns.

Updated Jun 28, 2026
One-click install
npx skills add https://github.com/412181-HerediaLara/ScaffoldingBE-FE --skill java-junit-412181-heredialara
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: java-junit
Source: https://github.com/412181-HerediaLara/ScaffoldingBE-FE/tree/main/BE/.agents/skills/java-junit
Command: npx skills add https://github.com/412181-HerediaLara/ScaffoldingBE-FE --skill java-junit-412181-heredialara

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing consistent, well-structured unit tests in Java is challenging when developers are unsure of JUnit 5 conventions, annotation usage, or how to implement data-driven tests. This Skill provides best practices for creating maintainable JUnit 5 test suites. ## Core Features & Use Cases - Standard Test Structure: Enforces AAA pattern, descriptive naming conventions, lifecycle annotations (@BeforeEach, @BeforeAll), and @DisplayName usage. - Parameterized Tests: Covers @ValueSource, @MethodSource, @CsvSource, @CsvFileSource, and @EnumSource for data-driven testing. - Assertions & Mocking: Recommends Assertions API, AssertJ, assertThrows, assertAll, and Mockito with @Mock/@InjectMocks for isolation. - Use Case: A backend developer needs to reach 95% JaCoCo coverage on a Spring service. Use this Skill to generate organized, parameterized JUnit 5 tests with proper mocking of repository dependencies. ## Quick Start Write JUnit 5 unit tests for my Calculator class including parameterized tests for edge cases.

Frequently Asked Questions about java-junit

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write parameterized tests in JUnit 5?

Use @ParameterizedTest with a source annotation: @ValueSource for literal values, @CsvSource for inline comma-separated data, @MethodSource for a factory method returning a Stream, or @EnumSource for enum constants. Add the junit-jupiter-params dependency to your project.

What is the best naming convention for JUnit test methods?

Use a descriptive pattern like methodName_should_expectedBehavior_when_scenario, and add @DisplayName for human-readable labels. Follow the Arrange-Act-Assert structure and keep each test focused on a single behavior.

How do I mock dependencies in JUnit 5 with Mockito?

Annotate dependencies with @Mock and the class under test with @InjectMocks to let Mockito create and inject mocks automatically. Designing classes against interfaces makes mocking significantly easier.

Does JUnit 5 support grouping and ordering tests?

Yes. Use @Tag to categorize tests, @Nested for inner-class grouping, and @TestMethodOrder with @Order when execution order is strictly necessary. Use @Disabled with a reason to temporarily skip tests.

How do I test exceptions in JUnit 5?

Use assertThrows to verify that code throws an expected exception, or assertDoesNotThrow for the opposite case. Group related checks with assertAll so all assertions are evaluated before the test fails.