java-unit-test-generator

java-unit-test-generator is a skill for Claude Code, Codex from timwukp/agent-skills-best-practice. It costs 46 tokens per session (971 once invoked), scanned A, original, MIT.

A guided tool for generating JUnit tests, which are automated checks for Java code, one small batch at a time.

In plain words
What is it for?
Use it to add tests to Java classes with JUnit 4, JUnit 5, or TestNG, optionally using mocking libraries such as Mockito or EasyMock.
Why use it?
It structures test creation around normal cases, errors, and edge cases while requiring validation before more tests are added.

Skill for Claude CodeCodex

Part of the engineering-skills plugin — 18 skills shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/timwukp/agent-skills-best-practice/java-unit-test-generator
Any agent
npx skills add timwukp/agent-skills-best-practice --skill java-unit-test-generator
Clone the repo
git clone --depth 1 https://github.com/timwukp/agent-skills-best-practice

Made for: Claude Code, Codex.

Or install engineering-skills, the plugin that ships this one along with the rest of its 18 skills.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for java-unit-test-generator

README.md
[![agentmods](https://agentmods.dev/badge/skills/timwukp/agent-skills-best-practice/java-unit-test-generator.svg)](https://agentmods.dev/skills/timwukp/agent-skills-best-practice/java-unit-test-generator)
Your own site
<a href="https://agentmods.dev/skills/timwukp/agent-skills-best-practice/java-unit-test-generator"><img src="https://agentmods.dev/badge/skills/timwukp/agent-skills-best-practice/java-unit-test-generator.svg" alt="Measured on agentmods" height="20"></a>
Per session 46 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 971 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00046 $0.00971
Opus 5 $0.00023 $0.00485
Sonnet 5 $0.00009 $0.00194
Haiku 4.5 $0.00005 $0.00097

Measured 5d ago against content hash eb7ede935997, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

java-unit-test-generator scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.

The scan reads SKILL.md. This mod also ships 1 executable file (scripts/validate_tests.py), listed below but not scanned — reading those needs a real analyzer, not pattern matching.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/skills/java-unit-test-generator/SKILL.md · 138 lines

How it starts

The opening of the file, as written. The whole thing — 138 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Java Unit Test Generator

Instructions

Step 1: Scope Definition

Before generating tests, ask:

  1. Which class/method?
  2. Coverage goal? (Basic = happy path | Standard = + errors | Comprehensive = + edge cases)
  3. Framework? (JUnit 4, JUnit 5, TestNG)
  4. Mocking? (Mockito, EasyMock, none)

Provide an upfront estimate: 10-15 credits per method.

Step 2: Generate 3 Tests Per Batch

For each method, generate exactly 3 tests:

  1. Happy path
  2. Error handling
  3. Edge case

Use this structure:

@Test
@DisplayName("Should [expected behavior] when [condition]")
void test[MethodName][Scenario]() {
    // Given - setup
    // When - execute
    // Then - verify
}

STOP after each batch. Ask the user to run and confirm before continuing.

Step 3: Validation Gate

Do NOT generate more tests until the user confirms the current batch works.

Validation command:

python scripts/validate_tests.py <TestClassName>

Step 4: Fix or Skip (Max 2 Attempts)

If tests fail:

  • Attempt 1: Fix compilation errors (imports, syntax)
  • Attempt 2: Fix logic errors (assertions, test data)
  • After 2 failures: Skip the test, document the issue, and move on

When skipping, say:

"This test failed twice. Skipping to preserve credits. Issue: [describe]. Options: (1) skip, (2) provide more context, (3) simplify scope."

Never attempt the same fix more than twice. Mark flaky tests @Disabled.

Step 5: Iterate or Finish

After a passing batch, offer:

  • 3 more tests for the same method
  • Move to next method
  • Stop and produce summary

Step 6: Summary Report

Methods Tested: N
Total Tests: N
Skipped: N (with reasons)
Coverage: happy path / error / edge case breakdown

Measuring Credit Cost for Your Code

Credit costs vary by Kiro account, model, and code complexity. To get accurate numbers for your environment, follow these steps.

1. Establish your baseline (one-time)

Run the built-in benchmark with a simple sample class:

Read the full file on GitHub · 138 lines

Files

What ships with it

4 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 5d ago First seen · 138 lines · 46 tokens per session scan A eb7ede935997

Subscribe to this mod's changes

java-unit-test-generator is a skill published in the GitHub repository timwukp/agent-skills-best-practice (10 stars, last pushed today), licensed MIT. It adds 46 tokens to every session and 971 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

java-regression-test-generator

Automatically generate regression tests for Java codebases by analyzing changes between old and new code versions. Use when users need to: (1) Generate tests after refactoring or code changes, (2) Ensure previously tested behavior still works in new versions, (3) Cover modified or newly added code paths, (4) Migrate…

ArabelaTso/Skills-4-SE · 111 tokens

111-java-maven-dependencies

Use when you need to add or evaluate Maven dependencies that improve code quality or domain modeling — including nullness annotations (JSpecify), static analysis (Error Prone + NullAway), functional programming (VAVR), architecture testing (ArchUnit), or money and currency support (JavaMoney) — and want a…

jabrena/plinth · 133 tokens

130-java-testing-strategies

Use when you need to apply testing strategies for Java code — RIGHT-BICEP to guide test creation, A-TRIP for test quality characteristics, or CORRECT for verifying boundary conditions. This should trigger for requests such as Review Java code for testing strategies; Apply RIGHT-BICEP testing strategies in Java code…

jabrena/plinth · 96 tokens

incremental-java-programmer

Incrementally implement new features in Java repositories from natural language descriptions. Use when adding functionality to existing Java codebases (Maven or Gradle projects). Takes a feature description as input and outputs modified repository with implementation code, corresponding JUnit tests, and verification…

ArabelaTso/Skills-4-SE · 78 tokens

131-java-testing-unit-testing

Use when you need to review, improve, or write Java unit tests — including migrating from JUnit 4 to JUnit 5, adopting AssertJ for fluent assertions, structuring tests with Given-When-Then, ensuring test independence, applying parameterized tests, mocking dependencies with Mockito, verifying boundary conditions…

jabrena/plinth · 160 tokens

421-frameworks-quarkus-testing-unit-tests

Use when you need to write fast unit tests for Quarkus applications — including pure tests with @ExtendWith(MockitoExtension.class), @QuarkusTest with @InjectMock for full CDI mock replacement, @InjectSpy for partial CDI bean mocking, REST Assured for resource-focused tests, @ParameterizedTest with @CsvSource /…

jabrena/plinth · 205 tokens