java-junit

Write and review JUnit 5 unit tests with Mockito isolation and AssertJ assertions.

Updated Sep 10, 2026
One-click install
npx skills add https://github.com/serpro-workshop-fortaleza/sifap-modernization-paula --skill java-junit-serpro-workshop-fortaleza
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: java-junit
Source: https://github.com/serpro-workshop-fortaleza/sifap-modernization-paula/tree/main/.github/skills/java-junit
Command: npx skills add https://github.com/serpro-workshop-fortaleza/sifap-modernization-paula --skill java-junit-serpro-workshop-fortaleza

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing consistent, well-isolated unit tests for Java business logic is hard to standardize across a team. This Skill codifies JUnit 5 best practices so every test follows the same structure, naming, isolation, and traceability conventions. ## Core Features & Use Cases - Standardized Test Structure: Enforces the Arrange-Act-Assert pattern, descriptive test naming, lifecycle annotations (@BeforeEach, @BeforeAll), and @DisplayName usage. - Parameterized & Data-Driven Tests: Guides the use of @ValueSource, @CsvSource, @CsvFileSource, @MethodSource, and @EnumSource to cover boundary values and edge cases. - Isolation with Mockito and AssertJ: Applies @Mock and @InjectMocks for dependency isolation and fluent AssertJ assertions for readable failures, plus REQ-ID traceability comments. - Use Case: When modernizing a legacy payment system to Java 21, ask the AI to write unit tests for a tax calculation service and receive tests that are isolated, parameterized, and traceable to requirements. ## Quick Start Write JUnit 5 unit tests for this service class using Mockito to isolate its dependencies and parameterized tests to cover the boundary values.

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?

Annotate the method with @ParameterizedTest instead of @Test and supply arguments via a source annotation. Use @ValueSource for single literals, @CsvSource for inline multi-parameter rows, @CsvFileSource for CSV files, @MethodSource for factory methods, and @EnumSource for enum constants.

How to mock dependencies in JUnit 5 with Mockito?

Add @ExtendWith(MockitoExtension.class) to the test class, declare dependencies with @Mock, and inject them into the class under test with @InjectMocks. Stub behavior with when(...).thenReturn(...) so the unit test never touches real databases, clocks, or networks.

Should I use AssertJ or JUnit assertions for unit tests?

AssertJ's fluent assertThat(...) is preferred because it produces readable failure messages and rich type-specific checks. JUnit's built-in assertions like assertEquals and assertTrue remain available, and assertThrows or assertThatThrownBy both work for verifying exceptions.

Does spring-boot-starter-test include JUnit 5 and Mockito?

Yes, spring-boot-starter-test bundles JUnit 5 including junit-jupiter-params, Mockito, and AssertJ, so no additional test dependencies are needed. Run the suite with ./mvnw test or ./gradlew test using the standard src/test/java layout.

When should I use Spring Boot slice tests instead of plain JUnit unit tests?

Use plain JUnit 5 unit tests for isolated business logic with mocked collaborators. Switch to Spring Boot slice tests like @WebMvcTest or @DataJpaTest, or Testcontainers-based integration tests, when you need the Spring context, web layer, or a real database involved.