java-unit-tests

Guide Java developers in writing JUnit 5 unit tests with AssertJ and Mockito.

Updated Dec 2, 2025
One-click install
npx skills add https://github.com/Kacper99/kacpers-marketplace --skill java-unit-tests
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: java-unit-tests
Source: https://github.com/Kacper99/kacpers-marketplace/tree/main/plugins/java/skills/java-test-writer
Command: npx skills add https://github.com/Kacper99/kacpers-marketplace --skill java-unit-tests

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Java developers often struggle to write consistent, maintainable unit tests that verify behavior without coupling to implementation details.

Core Features & Use Cases

  • Test Structure: guidelines for naming, phase annotations, and isolation.
  • Mocking Strategy: recommendations to avoid mocking domain objects and favor fakes.
  • Assertion Guidelines: prefer AssertJ, fluent chaining, and collection assertions.
  • Test Data & Builders: guidance on building test fixtures and reusable builders.
  • Organization: nested tests and grouping scenarios for readability.

Quick Start

Create a simple unit test skeleton for a service with a mock dependency.

Frequently Asked Questions about java-unit-tests

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

FAQPage Schema
How do I structure maintainable Java unit tests with JUnit 5?

Avoid mocking domain objects in Java unit tests by favoring fakes and reusable builders to construct test fixtures, ensuring tests verify behavior without coupling to implementation details.

How do I write fluent assertions in Java unit tests?

Write fluent assertions in Java unit tests by using AssertJ, which provides fluent chaining and expressive collection assertions to verify application layer behavior cleanly.

What is the best way to mock external dependencies in Java unit tests?

The best way to mock external dependencies in Java unit tests is using Mockito to isolate application layers, while avoiding mocking domain objects and favoring fakes instead.

When should I use nested tests in JUnit 5?

Use nested tests in JUnit 5 to group related scenarios and improve test readability, ensuring single assertions per test and maintaining strict isolation across typical Java projects.