MCPInstall

java-junit

Write, review and fix Java unit tests with JUnit 5 and JUnit 6 (Jupiter), AssertJ and Mockito: assertions, parameterized and nested tests, mocking rules, deterministic time and randomness, Surefire vs Failsafe, JaCoCo coverage, optional PIT mutation testing, and guardrails for agents (never skip or delete failing tests). Use when adding, refactoring or debugging tests in Maven or Gradle projects. Framework-neutral.

Installs
11.7K
Last 24h
+14
Trending rank
#7150
Security
Warn

Install

Works with every agent the skills CLI supports.

npx skills add https://github.com/github/awesome-copilot --skill java-junit
  1. 01

    Install

    Run the command in your project. The CLI asks which agents to install for.

  2. 02

    Describe the task

    Ask your agent for something this skill covers. It loads java-junit automatically when relevant.

  3. 03

    Review the result

    The agent follows the SKILL.md steps, scripts and references bundled with the skill.

Security audits

Independent scans of the skill's instructions and bundled files.

Gen Agent Trust Hub PassSAFE ·This skill provides standard guidelines and configurations for Java testing using JUnit, AssertJ, and Mockito. It includes best practices for maintaining test suites and specific build configurations for Maven and Gradle. No security risks were identified.
Socket PassNo alerts
Snyk PassLOW ·Risk: LOW · No issues
Runlayer WarnMEDIUM ·1/1 file flagged
ZeroLeaks PassNONE ·Score: 93/100 · 2 sections analyzed

SKILL.md

The instructions your agent reads when the skill is triggered.

Java Testing with JUnit 5/6, AssertJ and Mockito

Framework-neutral guidance for fast, deterministic unit tests. For Spring slices use spring-boot-testing (if installed); for real databases/brokers in Docker use java-testcontainers; for failures you cannot explain, java-debugging.

First: detect, don't impose

  1. Read pom.xml/build.gradle*: JUnit version (junit-jupiter, junit-bom, or inherited from a Spring Boot BOM), assertion library, Mockito, Surefire/Failsafe versions, Java release.
  2. Copy the conventions already in src/test/java (naming, assertion library, static imports, mocking style). Do not introduce AssertJ, Mockito or JaCoCo into a project that lacks them without asking.
  3. Never bump the JUnit major version implicitly; upgrading is its own task (see java-upgrade if installed).

JUnit 5 vs JUnit 6

JUnit 5 (last 5.14.x)JUnit 6 (6.0 released; 6.1.x current)
Java baseline817 (verified in the published Gradle module metadata)
VersioningPlatform 1.x, Jupiter 5.x, Vintage 5.xOne version number for Platform, Jupiter and Vintage
APIorg.junit.jupiter.api.*Same packages; the Jupiter tests in this skill compile and pass unchanged on 5.14.4 and 6.0.3
Removed in 6.0MethodOrderer.Alphanumeric, the deprecated two-argument InvocationInterceptor.interceptDynamicTest(Invocation, ExtensionContext) overload (the three-argument one remains), junit.jupiter.tempdir.scope, @CsvFileSource(lineSeparator)
CSVunivocity-parsersFastCSV: stricter parsing (no characters after a closing quote); header-field options now apply to headers
Otherjunit-jupiter-migrationsupport deprecated; invalid enum-style config values now fail discovery; @Nested class order deterministic but non-obvious

Source: JUnit 6.0.0 release notes (https://docs.junit.org/6.0.0/release-notes.html). Read the notes for the target version (https://docs.junit.org/current/release-notes/) and prefer them over this table. JUnit 4 tests need the Vintage engine; do not mix org.junit.Test and org.junit.jupiter.api.Test in one class.

Dependencies (same for 5 and 6; verified with Maven and Gradle): import org.junit:junit-bom, then declare org.junit.jupiter:junit-jupiter (aggregates api, params, engine) with test scope. Gradle 9 additionally requires testRuntimeOnly("org.junit.platform:junit-platform-launcher") (verified: without it the test executor fails with "Failed to load JUnit Platform") and tasks.test { useJUnitPlatform() }. Maven needs Surefire 3.x (verified with 3.6.0).

Assertions

Match the project's library. Plain Jupiter rules: expected value first, lazy Supplier messages, assertAll, assertThrowsExactly, timeouts. (The separate instructions/java-junit5-assertions.instructions.md resource has the longer version but is not installed with this skill.) If the project uses AssertJ, prefer it for collections, strings and exceptions; patterns (soft assertions, assertThatThrownBy, extracting, containsExactly, usingRecursiveComparison) are in references/assertj-and-mockito.md.

  • Assert on outcomes and state, not on how many times internals were called.
  • Compare values; avoid bare assertNotNull.
  • Never catch AssertionError/Exception to make a test pass.

Mocking (Mockito)

  • Mock collaborators across a boundary (repository, HTTP client, clock, message sender). Do not mock value objects, records, collections, String, or the class under test; use real instances or simple fakes.
  • Prefer a hand-written fake over a mock when the interaction is stateful.
  • Use @ExtendWith(MockitoExtension.class) with @Mock/@InjectMocks/@Captor. Strict stubs are the default there, so an unused stub fails the test (UnnecessaryStubbingException). Fix the test; relax with @MockitoSettings(strictness = Strictness.LENIENT) only for a justified shared setup.
  • Mockito 5 uses the inline mock maker by default. On JDK 21+ it may self-attach and print a dynamic-agent warning. With Mockito 5.14.0+, register mockito-core as a -javaagent instead (setup for Maven and Gradle in references/assertj-and-mockito.md, verified on JDK 21 and 25). Check the resolved version first: earlier 5.x jars lack Premain-Class and cannot be used as the agent. Ask before upgrading; otherwise use the instrumentation setup documented for the installed version.
  • Mockito 5 requires Java 11+. Its default inline mock maker does not work on GraalVM native image, where the subclass mock maker is appropriate (Mockito 5.0.0 release notes, https://github.com/mockito/mockito/releases/tag/v5.0.0).
  • Avoid mockStatic/mockConstruction; wrap the static call behind an interface.

Determinism

  • Time: inject java.time.Clock (Clock.fixed(...)) and call Instant.now(clock); avoid Instant.now()/LocalDate.now() in code under test.
  • Randomness: inject a Random/RandomGenerator with a fixed seed; log the seed if generated.
  • Do not depend on default locale, time zone, file encoding, network, or wall-clock sleeps. Set them explicitly (newer 6.x releases add built-in locale/time-zone/system-property extensions; check the release notes of your version, otherwise use try/finally).

Unit vs integration tests

Unit (*Test)Integration (*IT)
MavenSurefire, mvn testFailsafe, mvn verify
Gradletest taskseparate integrationTest task (JVM Test Suite) wired into check
Speedmilliseconds, no I/Omay use Docker/DB

Surefire defaults pick *Test, Test*, *Tests, *TestCase; Failsafe picks *IT, IT*, *ITCase. Failsafe needs the integration-test and verify goals bound and is run by mvn verify, not mvn test. Alternatively split by @Tag. For databases and brokers see java-testcontainers; for Spring slices see spring-boot-testing. Full build snippets: references/build-setup.md.

Coverage and mutation testing (optional)

  • JaCoCo: add only if the project uses it or the user asks. With Surefire/Failsafe use <argLine>@{argLine} ...</argLine> so the JaCoCo agent is not overwritten.
  • Coverage is a smell detector, not a goal; never add assertion-free tests to raise a number, and do not add a coverage gate the project lacks.
  • PIT (mutation testing) is slow; run it on changed classes only if the project already uses it or the user asks (see references/build-setup.md, which records a verified pitest-maven + JUnit 5 plugin run).

Agent guardrails

  1. Never delete, comment out, @Disabled, weaken (looser assertion, wider tolerance, swallowed exception) or skip a failing test to get green. Find the cause.
  2. Decide which side is wrong, the test or the production code. If the fix changes production behavior, stop and ask the user first; if the test encodes an obviously stale expectation, say so and propose the change.
  3. Do not add -DskipTests, -Dmaven.test.skip, -x test or failIfNoTests=false to make a build pass.
  4. Do not mock the class under test or assert on mock internals to "prove" correctness.
  5. Run the narrowest test first, then the full build:
    • Maven: mvn -q -Dtest=OrdersTest test (one method: -Dtest='OrdersTest#place_should_saveAndNotify_when_itemValid'), then mvn verify.
    • Gradle: ./gradlew test --tests 'demo.OrdersTest', then ./gradlew check. Prefer the project wrapper (./mvnw, ./gradlew) when present.
  6. Flaky test: reproduce by rerunning, then remove the nondeterminism (time, order, shared state, async waits); do not add retries.
  7. New code gets new tests beside the existing ones, in the same style: happy path, boundaries, error cases.

References

  • references/assertj-and-mockito.md: AssertJ patterns, Mockito strictness/captors/agent setup, when not to mock.
  • references/build-setup.md: Maven and Gradle (Kotlin DSL) setups for JUnit 5/6, Failsafe split, JaCoCo, PIT.

FAQ

What does the java-junit skill do?

Write, review and fix Java unit tests with JUnit 5 and JUnit 6 (Jupiter), AssertJ and Mockito: assertions, parameterized and nested tests, mocking rules, deterministic time and randomness, Surefire vs Failsafe, JaCoCo coverage, optional PIT mutation testing, and guardrails for agents (never skip or delete failing tests). Use when adding, refactoring or debugging tests in Maven or Gradle projects. Framework-neutral.

How do I install java-junit?

Run npx skills add https://github.com/github/awesome-copilot --skill java-junit in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/java-junit/ (personal) or .claude/skills/java-junit/ (project).

Which AI agents can use java-junit?

Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.

Is java-junit safe to install?

Security partners have reviewed it: Gen Agent Trust Hub passed; Socket passed; Snyk passed; Runlayer flagged items to review; ZeroLeaks passed. As with any skill, read the SKILL.md and bundled scripts before installing.

Who maintains java-junit?

It is published by github in github/awesome-copilot, and it is an official skill from the maker of the technology it covers. It has 11,684 recorded installs.

More from github/awesome-copilot

View all →

git-commit

github/awesome-copilot

Use this skill when the user wants to make a Git commit or split changes into more than one commit. Also use it when the user types "/commit" or asks for a conventional commit. The skill examines the diff, stages the related files, writes a Conventional Commits message, and runs git commit. Do not use it when the user wants only a commit message and no commit. Do not use it to push, open a pull request, rebase, or change the commit history.

OfficialCode Quality & Workflow47.4K installs

excalidraw-diagram-generator

github/awesome-copilot

Generate Excalidraw diagrams from natural language descriptions. Use when asked to "create a diagram", "make a flowchart", "visualize a process", "draw a system architecture", "create a mind map", or "generate an Excalidraw file". Supports flowcharts, relationship diagrams, mind maps, and system architecture diagrams. Outputs .excalidraw JSON files that can be opened directly in Excalidraw.

OfficialDocs & Writing31.9K installs

multi-stage-dockerfile

github/awesome-copilot

Create optimized multi-stage Dockerfiles for any language or framework

Official29.8K installs

documentation-writer

github/awesome-copilot

Diátaxis Documentation Expert. An expert technical writer specializing in creating high-quality software documentation, guided by the principles and structure of the Diátaxis technical documentation authoring framework.

OfficialDocs & Writing27.9K installs

prd

github/awesome-copilot

Generate high-quality Product Requirements Documents (PRDs) for software systems and AI-powered features. Includes executive summaries, user stories, technical specifications, and risk analysis.

Official24.1K installs

refactor

github/awesome-copilot

Surgical code refactoring to improve maintainability without changing behavior. Covers extracting functions, renaming variables, breaking down god functions, improving type safety, eliminating code smells, and applying design patterns. Less drastic than repo-rebuilder; use for gradual improvements.

OfficialCode Quality & Workflow22.4K installs

Popular backend & apis skills

View category →

find-skills

vercel-labs/skills

Helps users discover and install agent skills when they ask questions like "how do I do X", "find a skill for X", "is there a skill that can...", or express interest in extending capabilities. This skill should be used when the user is looking for functionality that might exist as an installable skill.

OfficialBackend & APIs4.1M installs

entra-app-registration

microsoft/azure-skills

Guides Microsoft Entra ID app registration, OAuth 2.0 authentication, and MSAL integration. USE FOR: create app registration, register Azure AD app, configure OAuth, set up authentication, add API permissions, generate service principal, MSAL example, console app auth, Entra ID setup, Azure AD authentication. DO NOT USE FOR: Key Vault secrets (use azure-keyvault-expiration-audit), general Azure resource security guidance.

OfficialBackend & APIs566.7K installs

This skill should be used when the user wants to "write agent code", "build an agent with ADK", "add a tool", "create a callback", "define an agent", "use state management" — in a project that needs ADK (Agent Development Kit) API patterns and code examples. It provides a quick reference for agent types, tool definitions, orchestration patterns, callbacks, state management, the graph Workflow API, and reference recipes to study. Do NOT use for scaffolding (use google-agents-cli-scaffold) or deployment (use google-agents-cli-deploy).

Backend & APIs514.8K installs

embedded-captions

heygen-com/hyperframes

Add captions or subtitles to an existing single-subject talking-head video without editing the footage. Use for plain verbatim captions, cinematic captions embedded behind the subject, VFX captions, “炸/特效/酷炫字幕,” or a named identity from the 35-style catalog. Route by visual identity, not by backend engine. The quiet anchor rail is the default; embed every word only when the user explicitly wants a fully cinematic treatment. The workflow runs locally end to end, including transcription and subject matting; split multi-shot footage before applying it.

Backend & APIs453.3K installs

entra-agent-id

microsoft/azure-skills

Provision Microsoft Entra Agent Identity Blueprints, BlueprintPrincipals, and per-instance Agent Identities via Microsoft Graph, and configure OAuth 2.0 token exchange (fmipath, OBO, cross-tenant) including the Microsoft Entra SDK for AgentID sidecar. USE FOR: Agent Identity Blueprint, BlueprintPrincipal, agent OAuth, fmipath token exchange, agent OBO, Workload Identity Federation for agents, polyglot agent auth, Microsoft.Identity.Web.AgentIdentities. DO NOT USE FOR: standard Entra app registration (use entra-app-registration), Microsoft Foundry agent authoring (use microsoft-foundry).

OfficialBackend & APIs336.6K installs

neon

neondatabase/agent-skills

Overview of Neon, a complete set of cloud backend primitives around Lakebase Postgres: Auth, Object Storage, Functions, the AI Gateway, and Realtime. Start here to choose Neon for undecided login, files, APIs, and LLM calls, set up the CLI or MCP server, and follow the branch-first workflow. Use when building an app or backend on Neon, or when "Neon" or "Lakebase Postgres" is mentioned. Child skill neon-postgres wins for an existing DATABASEURL, SQL, schema, inspect, or search. Child skill neon-auth wins for login, users, sessions, identity routing, and Managed Better Auth setup. Child skill neon-realtime wins for live queries in reactive apps and agents. Also use for object storage, S3, buckets, serverless functions, function triggers, cron, AI gateway, LLM calls, realtime, logs, Loki, Grafana, observability, postgres, database, backend, Claimable Neon, neon.new, or a no-signup database.

Backend & APIs237.1K installs