java-unit-test-generator

Solid

Generates JUnit unit tests for Java classes with loop prevention and incremental generation. Triggers on: "generate unit tests", "create JUnit tests", "test Java class", "add test coverage".

Testing & QA 7 stars 3 forks Updated today MIT

Install

View on GitHub

Quality Score: 81/100

Stars 20%
30
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
80
License 10%
100
Description 5%
100

Skill Content

# 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:...

Details

Author
timwukp
Repository
timwukp/agent-skills-best-practice
Created
4 months ago
Last Updated
today
Language
Python
License
MIT

Similar Skills

Semantically similar based on skill content — not just same category