# Spring Boot Unit Test Generator

> Point your agent at a controller, service, or repository and get a production-quality JUnit 5 + Mockito test suite — edge cases included, quality-gated, and run before delivery.

Spring Boot Unit Test Generator is a paid AI agent skill on Agensi by william Harris, in Testing & Debugging. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: $9 (one-time purchase)
- Creator: [william Harris](https://www.agensi.io/creators/william-harris)
- Category: [Testing & Debugging](https://www.agensi.io/skills/testing-debugging)
- Version: 1.0
- Last updated: 2026-12-02
- Security: scan passed (2026-12-02); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/spring-boot-unit-test-generator
- Tags: testing, code-review, spring-boot, java, junit-5, mockito, unit-tests, test-generation

## About this skill

Spring Boot Unit Test Generator — JUnit 5 + Mockito tests that catch real bugs

Most AI-generated tests are decoration: they mock everything, assert almost nothing, and pass against code that is quietly broken. This skill generates tests the way a careful engineer writes them — and proves it with a rehearsal in which the generated suite catches 8 out of 8 planted bugs (off-by-one stock check, wrong discount math, a null-code NPE, a swallowed persistence exception, a wrong HTTP status code, stock decremented by 1 instead of by quantity, a tax rounding error, and missing quantity validation). It detects your stack first (Spring Boot version, jakarta/javax, @MockBean/@MockitoBean, JUnit version, existing test style) so tests compile in your project. Every public method gets a behavior list before any code: happy path, exact boundary values, null and empty inputs, exception paths, side effects, idempotency. Tests are layer-correct: @WebMvcTest + MockMvc for controllers asserting exact status codes and JSON bodies; plain Mockito for services with argument captors verifying saved state; @DataJpaTest only for custom repository queries. A bundled quality gate flags assertion-free tests, verify-only tests, mocking the class under test, Thread.sleep, and real-clock reads. The suite is run before delivery: compile errors are fixed, and any test exposing a real bug is reported as a finding with the failing input — never quietly weakened to pass. No credentials, no network calls, nothing uploaded — the skill reads only the files you point it at.

### What it does
1. Detects your stack and matches your Spring Boot/JUnit versions and test style.
2. Builds a per-method test plan (boundaries, nulls, exceptions, side effects) before writing code.
3. Generates layer-correct tests: @WebMvcTest controllers, Mockito services with captors, @DataJpaTest custom queries.
4. Covers production edge cases: ordering exactly the remaining stock, null discount codes, half-cent money rounding, repositories throwing mid-save, negative quantities.
5. Runs a quality gate that rejects assertion-free or verify-only tests.
6. Executes the suite and reports real bugs as findings instead of weakening tests.

### How it works
1. Stack detection from your build file.
2. Test plan per public method.
3. Per-layer test generation.
4. Quality-gate scan.
5. Run the suite, fix compile errors, report findings.

### What's included
- SKILL.md (full workflow)
- reference/test-checklist.md (planning + edge-case catalog)
- reference/mocking-guide.md (mock/fake/real decisions, captors, Clock injection, H2 vs Testcontainers)
- reference/examples.md (ten worked examples)
- reference/rehearsal.md (complete 8-bug rehearsal with verified results)
- examples/sample-project/ (runnable Maven project — mvn test passes)
- scripts/test_quality_check.py (quality-gate scanner, Python 3 stdlib only)

### Who it's for
Java/Spring Boot developers who need tests for existing code; teams raising coverage on legacy services; anyone tired of AI-generated tests that assert nothing; adding tests before a refactor; verifying a bug fix with a regression test; preparing a module for release.

## Requires

- spring-boot-starter-test
- Python 3 (quality-gate script, stdlib only)
- Optional: H2 or Testcontainers (repository tests)

No credentials or network calls; reads only the files you point it at. If spring-boot-starter-test is missing, the skill shows the dependency to add.

## Known limitations

Targets Spring Boot 3.x / JUnit 5 / Mockito 5 conventions; Boot 2.x differences are documented in the mocking guide but not rehearsed. Repository tests need H2 or Testcontainers. The quality gate checks test form and smells; it cannot judge whether a business assertion matches your spec. Requires spring-boot-starter-test in the project (the skill shows the dependency if missing).

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the Spring Boot Unit Test Generator skill from Agensi" and describe your task.
3. Buy it on the listing or let your agent ask you first; your agent then loads it from Agensi when it needs it. Every paid skill has a money-back guarantee: https://www.agensi.io/docs/money-back-guarantee

## Frequently asked questions

### Will the tests compile in my project?

The skill detects your Spring Boot and JUnit versions first (jakarta/javax, @MockBean vs @MockitoBean) and matches your existing test style.

### What if a generated test fails?

Compile errors are fixed. A test that exposes a real bug in your code is reported as a finding with the failing input — never weakened to pass.

### Does it mock everything?

No. Controllers use @WebMvcTest, repositories use @DataJpaTest for custom queries, and pure components are tested for real; the mocking guide decides mock vs fake vs real per dependency.

### Which Spring versions are supported?

Rehearsed on Spring Boot 3.4.1 / JUnit 5 / Mockito 5; Boot 2.x differences are called out in the guide.

### Does it upload my code anywhere?

No. It reads only the files you point it at; the quality-gate script is local and read-only.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
