write-junit

Create JUnit 5 unit tests with Mockito and Testcontainers for Java classes.

1|Updated Apr 21, 2026
One-click install
npx skills add https://github.com/sswapnil2/ai-config-fintech --skill write-junit
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: write-junit
Source: https://github.com/sswapnil2/ai-config-fintech/tree/main/skills/write-junit
Command: npx skills add https://github.com/sswapnil2/ai-config-fintech --skill write-junit

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Writing reliable JUnit 5 tests for Java classes ensures correct behavior and guards against regressions, with Mockito for collaborators and Testcontainers for integration when needed.

Core Features & Use Cases

  • Unit tests for pure logic with mocks, including edge cases and error paths.
  • Integration tests using Testcontainers and Spring contexts when data stores or external services are involved.
  • Use Case: validate a service that interacts with a repository by verifying interactions and outcomes.

Quick Start

Create a skeleton test file for a public method using Mockito and JUnit 5.

Frequently Asked Questions about write-junit

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

FAQPage Schema
How do I write JUnit 5 unit tests for Java services with Mockito?

Generate JUnit 5 unit tests for Java service classes by mocking collaborators with Mockito to validate behavior. This approach tests pure domain logic, including edge cases and error paths, while enforcing meaningful assertions to prevent regressions.

When should I use Testcontainers for Java integration testing?

Use Testcontainers for Java integration testing when data stores or external services like databases, Redis, or Mongo are involved. It spins up Spring contexts to validate real interactions, enforcing rules like no mocking of EntityManager or Jpa in integration tests.

Can I mock EntityManager in JUnit 5 integration tests?

No, you cannot mock EntityManager or Jpa in JUnit 5 integration tests. You must use Testcontainers with Spring contexts to validate real database interactions and enforce meaningful assertions without bypassing the actual data store layer.

What is the best way to avoid Thread.sleep in JUnit tests?

The best way to avoid Thread.sleep in JUnit tests is to enforce strict organizational rules during test generation. Create JUnit 5 tests that mock collaborators with Mockito for behavior validation, ensuring meaningful assertions without relying on arbitrary delays.

Does JUnit 5 work with Testcontainers for testing Redis interactions?

Yes, JUnit 5 works with Testcontainers for testing Redis interactions. When external services or data stores are involved, apply Testcontainers within Spring contexts to validate real interactions rather than mocking the data layer.