skillfed

test-quality

Test Quality guides you through writing maintainable Java tests using JUnit 5 and AssertJ. It covers the Arrange-Act-Assert pattern, collection and exception assertions, nested test organization, and parameterized testing to improve code coverage and test readability.

Test Quality writes high-quality JUnit 5 tests with AssertJ assertions for Java projects.

AI-generated summary based on this skill's SKILL.md

693 135 MIT updated by decebals

Install

decebals/claude-code-java/test-quality · repository language: Shell

git clone https://github.com/decebals/claude-code-java
cp -r claude-code-java/.claude/skills/test-quality ~/.claude/skills/test-quality
npx skillfed install decebals/claude-code-java/test-quality

Frequently asked questions

AI-generated answers based on this skill's SKILL.md and metadata

How do I write JUnit 5 tests for Java?

Test Quality helps you write JUnit 5 tests using the Arrange-Act-Assert pattern. Start by organizing your test class with @Test methods, set up your test data in the arrange phase, execute the code being tested in the act phase, and verify results using AssertJ assertions in the assert phase. Test Quality covers structuring tests with nested classes for better organization and using parameterized tests to reduce duplication.

What are the key differences between AssertJ and JUnit assertions?

Test Quality explains that AssertJ provides a fluent, chainable API with more readable assertions than JUnit's built-in methods. AssertJ offers richer matchers for collections, strings, and exceptions, supports soft assertions to check multiple conditions without stopping on first failure, and delivers clearer error messages. This makes AssertJ ideal for writing high-quality, maintainable tests that are easier to debug.

How to use AssertJ assertions effectively in tests?

Test Quality guides you through AssertJ's fluent syntax for common scenarios: use assertThat() with chainable methods like isEqualTo(), contains(), and hasSize() for collections. For strings, leverage startsWith(), endsWith(), and matches(). AssertJ also supports soft assertions via SoftAssertions class to verify multiple conditions, and specialized methods like assertThatThrownBy() for exception testing, all improving test readability and maintainability.

What are JUnit 5 best practices for test organization?

Test Quality recommends organizing tests with nested classes using @Nested to group related test cases by behavior or scenario, improving readability and structure. Use @DisplayName for clear test descriptions, @ParameterizedTest with various sources for testing multiple inputs, and the Arrange-Act-Assert pattern consistently. This approach enhances test coverage, makes tests self-documenting, and simplifies maintenance as your test suite grows.

How do I improve test coverage and quality in Java projects?

Test Quality teaches you to improve coverage by writing parameterized tests that check multiple scenarios with less code, using nested test classes to organize related tests, and leveraging AssertJ's collection and exception assertions for thorough verification. Focus on testing edge cases, exception handling, and async operations. Regular refactoring of tests using these patterns ensures your test suite remains maintainable and provides genuine value.

How can I test exception handling and async operations with JUnit 5?

Test Quality covers exception testing using AssertJ's assertThatThrownBy() to verify both exception type and message, and assertThatCode() for code that should not throw. For async operations, use JUnit 5's timeout support with @Timeout annotation and combine it with AssertJ assertions. These techniques ensure your error handling is robust and async code behaves correctly under various conditions.

SKILL.md

rendered from the published skill — quoted content, verbatim

Test Quality Skill (JUnit 5 + AssertJ)

Write high-quality, maintainable tests for Java projects using modern best practices.

When to Use

  • Writing new test classes
  • Reviewing/improving existing tests
  • User asks to "add tests" / "improve test coverage"
  • Code review mentions missing tests

Framework Preferences

JUnit 5 (Jupiter)
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import static org.assertj.core.api.Assertions.*;
AssertJ over standard assertions

Use AssertJ:

assertThat(plugin.getState())
    .as("Plugin should be started after initialization")
    .isEqualTo(PluginState.STARTED);

assertThat(plugins)
    .hasSize(3)
    .extracting(Plugin::getId)
    .containsExactly("plugin1", "plugin2", "plugin3");

Avoid JUnit assertions: ```java assertEquals(PluginState.STARTED, plugin.getState());

(truncated - see the full file via the links below)

Read as markdown · JSON record · Browse the source repository

File tree — 2 files
.claude/skills/test-quality/README.md
.claude/skills/test-quality/SKILL.md

Related skills

Tags

assertion-framework test-structure code-coverage mock-testing parameterized-tests exception-handling test-organization fluent-api