java-test-quality

Generates JUnit 5 tests with AssertJ assertions for Java code.

Updated Apr 20, 2020
One-click install
npx skills add https://github.com/UnterrainerInformatik/java-rdb-utils --skill java-test-quality-unterrainerinformatik
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: java-test-quality
Source: https://github.com/UnterrainerInformatik/java-rdb-utils/tree/main/.agents/skills/java-test-quality
Command: npx skills add https://github.com/UnterrainerInformatik/java-rdb-utils --skill java-test-quality-unterrainerinformatik

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing thorough, maintainable Java unit tests is time-consuming, and teams often end up with poorly named tests, weak assertions, or missing edge cases. This Skill guides the creation of high-quality JUnit 5 tests using AssertJ, enforcing consistent structure and naming conventions. ## Core Features & Use Cases - Test Generation: Produces JUnit 5 test classes following the Arrange-Act-Assert pattern with descriptive @DisplayName annotations and AssertJ fluent assertions. - Test Review & Improvement: Reviews existing test classes, suggests missing edge cases, replaces weak JUnit assertions with AssertJ, and identifies anti-patterns like testing implementation details. - Advanced Patterns: Covers nested test classes, parameterized tests, Mockito integration, soft assertions, exception testing, and async verification. - Use Case: Ask to add tests for a PluginManager class and receive a complete test suite covering happy paths, error conditions, and boundary cases, plus JaCoCo coverage configuration. ## Quick Start Ask the assistant to add unit tests with edge cases for a specific Java class or method in your project.

Frequently Asked Questions about java-test-quality

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

FAQPage Schema
How do I write JUnit 5 tests with AssertJ assertions?▼

Import org.junit.jupiter.api.Test and static org.assertj.core.api.Assertions, then structure each test with Arrange-Act-Assert. Use assertThat(...).isEqualTo(...) style fluent assertions instead of JUnit's assertEquals for more readable failures.

AssertJ vs JUnit assertions: which should I use?▼

AssertJ is preferred for its fluent, chainable API and descriptive failure messages. Statements like assertThat(list).hasSize(3).contains(item) read naturally and produce clearer errors than assertEquals or assertTrue equivalents.

How do I test exceptions in JUnit 5 with AssertJ?▼

Use assertThatThrownBy(() -> code()).isInstanceOf(MyException.class).hasMessageContaining("error"). This verifies both the exception type and message, and supports cause-chain checks with hasCauseInstanceOf.

Does this approach work with Mockito for mocking dependencies?▼

Yes. Combine @ExtendWith(MockitoExtension.class) with @Mock and @InjectMocks annotations, then stub with when(...).thenReturn(...) and verify interactions with verify(mock).method(). AssertJ handles the result assertions.

What code coverage should I aim for in Java unit tests?▼

Aim for 80% or higher line coverage on core business logic, complex algorithms, and error handling. Skip trivial getters, setters, and POJOs. Use the JaCoCo Maven plugin to generate reports and enforce thresholds.

Why are my parameterized tests not running in JUnit 5?▼

Parameterized tests require the junit-jupiter-params dependency and the @ParameterizedTest annotation with a source such as @ValueSource, @CsvSource, or @MethodSource. Missing the dependency is the most common cause.