# Generate Java Unit Tests

Java teams often need focused tests that match existing project style. This skill guides Claude, Codex, and Claude Code to create JUnit and Mockito tests with practical mocks.

## Install

```bash
npx skillstore add gavin-ali/java-unit-test
```

## Metadata

- Status: approved
- Slug: gavin-ali-java-unit-test
- Skillstore revision: r1
- Version status: missing
- Tree hash: 99d3f337dcdc6a93536be20903404d5ebc386a1906424b82b8c670534cdf71e8
- Author: gavin-ali
- GitHub username: gavin-ali
- License: MIT
- Repository: https://github.com/gavin-ali/java-unit-test-skills/tree/main/.trae/skills/java-unit-test
- Ref: a06681402992ceae98ba04d54cfd4ab004862696
- Supported tools: Claude, Codex, Claude Code
- Audit status: complete
- Agent install advisory: allowed
- Manual install advisory: allowed
- Artifact signature: available
- Audit attestation: unavailable
- Human verification: not\_verified
- Risk factors: scripts
- Quality score: 77
- Quality tier: bronze
- Public page: https://skillstore.pages.dev/skills/gavin-ali-java-unit-test
- Manifest: https://skillstore.pages.dev/api/skills/gavin-ali-java-unit-test/manifest

## Capabilities

- Identifies the class under test, public methods, constructors, and direct dependencies.
- Plans unit tests for normal paths, branch conditions, boundary values, and exception flows.
- Generates JUnit 5 and Mockito test structures that match common Java project layouts.
- Recommends mocks, spies, argument captors, and interaction checks for external dependencies.
- Organizes imports, test data builders, assertions, and test method names for maintainability.

## Use Cases

- Create service tests: Generate focused tests for Java services with repository, client, or cache dependencies.
- Improve branch coverage: Add tests for uncovered branches, boundary inputs, and exception cases in business logic.
- Standardize team testing: Apply a consistent JUnit and Mockito structure across classes and modules.

## Prompt Templates

### Create basic tests

```
Generate JUnit 5 tests for this Java class. Follow the existing package, naming, and assertion style.
```

### Add Mockito coverage

```
Review this service and create tests for success, validation, and dependency failure paths using Mockito.
```

### Improve coverage gaps

```
Use the coverage report and source class to add tests for uncovered branches and boundary cases.
```

### Design maintainable tests

```
Analyze this module, identify hard-to-mock dependencies, suggest small refactors, then create focused unit tests.
```

## Limitations

- It does not run the generated tests or verify build results by itself.
- It needs source files and project conventions to produce accurate tests.
- It focuses on unit tests, not full integration or end-to-end test suites.
- Custom frameworks or unusual build setups may require manual adjustment.

## Best Practices

- Provide the source class, related interfaces, and one existing test for style reference.
- Ask for behavior-focused assertions instead of broad object comparisons.
- Keep each test independent, fast, and clear about the scenario under test.

## Anti Patterns

- Do not ask for tests without providing the source class or dependency contracts.
- Do not overuse Spring context tests when simple Mockito tests are enough.
- Do not assert private implementation details that make tests fragile.

## Security Audit

- Audited at: 2026-07-06T15:23:33.865\+00:00
- Summary: The static dynamic import finding is a false positive caused by prose about Java static imports. The entropy heuristic is also a false positive because SKILL.md is readable Markdown guidance, not binary, encrypted, or obfuscated content.

## Stats

- Views: 178
- Downloads: 53
- Favorites: 0
- Popularity score: 0
