java-unit-test-expert

Generate JUnit 5 and Mockito tests for Spring Boot 2.1.x services and controllers.

Updated Feb 24, 2026
One-click install
npx skills add https://github.com/Xunzi229/skills --skill java-unit-test-expert
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: java-unit-test-expert
Source: https://github.com/Xunzi229/skills/tree/main/java-unit-test-expert
Command: npx skills add https://github.com/Xunzi229/skills --skill java-unit-test-expert

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill eliminates low-quality, non-repeatable, or incomplete Java unit tests by providing strict, actionable rules and ready-to-run JUnit 5 + Mockito test implementations that improve maintainability and coverage for Spring Boot codebases.

Core Features & Use Cases

  • Strict mocking and isolation: mock only dependencies of the system under test; never mock the SUT methods or DTO/POJO objects; use @WebMvcTest for controllers and Mockito extensions for other layers.
  • Robust assertions and patterns: unify numeric comparisons to avoid overload ambiguity, use ReflectionTestUtils for private field injection when necessary, and require @DisplayName on each test method.
  • Coverage-driven test design: produce normal, error, and boundary cases for each non-static, non-private method with the goal of >80% line coverage and include all necessary imports and annotations so tests are self-contained and runnable.
  • Typical use cases: adding controller/service tests for Spring Boot 2.1.x, improving flaky or incomplete tests, creating regression tests after refactors or bug fixes, and reviewing/enforcing test quality and conventions.

Quick Start

Generate JUnit 5 tests for the UserService in a Spring Boot 2.1.x project that mock only its dependencies, cover normal, exception, and boundary scenarios, and include all imports and annotations so the tests run immediately.

Frequently Asked Questions about java-unit-test-expert

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

FAQPage Schema
How do I generate JUnit 5 unit tests for a Spring Boot service?

To generate JUnit 5 unit tests for a Spring Boot service, provide the service class to generate self-contained, runnable tests using Mockito. It mocks only dependencies, covers normal, error, and boundary cases, and includes all necessary imports and annotations.

Why should I avoid mocking the system under test when writing Java unit tests?

You should avoid mocking the system under test in Java unit tests to ensure you are testing actual behavior rather than mock interactions. This skill enforces strict isolation by mocking only external dependencies and DTOs, never the SUT itself.

How do I fix flaky tests in a Spring Boot 2.1.x project?

To fix flaky tests in a Spring Boot 2.1.x project, apply strict mocking rules and robust assertion patterns using JUnit 5 and Mockito. This skill generates self-contained tests with unified numeric comparisons and proper isolation to prevent non-repeatable behavior.

Does this approach support generating tests for Spring Boot controllers?

Yes, this approach supports generating tests for Spring Boot controllers by utilizing the @WebMvcTest annotation. It produces runnable controller tests that mock only service dependencies, covering normal, exception, and boundary scenarios with all required imports.

What is the best way to increase unit test coverage for existing Java code?

The best way to increase unit test coverage for existing Java code is to design tests covering normal, error, and boundary cases for each non-static, non-private method. This skill generates coverage-driven JUnit 5 tests targeting over 80% line coverage.

Can I use ReflectionTestUtils for private field injection in JUnit 5 tests?

Yes, you can use ReflectionTestUtils for private field injection in JUnit 5 tests when necessary. This skill employs robust assertion patterns and ReflectionTestUtils to handle private field injection while maintaining strict dependency mocking and test isolation.