java-unit-test-generatorlisted
Install: claude install-skill timwukp/agent-skills-best-practice
# 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:
```java
@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:
```bash
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: