Testing Workflow
TDD Cycle
RED — failing test. GREEN — minimal code to pass. REFACTOR — clean up, tests stay green.
// RED: write test first
@Test void shouldCreateOrderWhenValidInput() {
StepVerifier.create(orderService.create(validCommand))
.assertNext(o -> assertThat(o.getStatus()).isEqualTo(OrderStatus.PENDING))
.verifyComplete();
}
// GREEN: ./gradlew test -> implement until pass
// REFACTOR: ./gradlew test jacocoTestReport -> clean up, verify coverage >= 80%
Test Pyramid
| Type |
Annotation |
Speed |
Use For |
| Unit |
@ExtendWith(MockitoExtension.class) |
Fast |
Service/domain logic |
| Controller (WebFlux) |
@SpringBootTest + @AutoConfigureWebTestClient |
Medium |
API contracts |
| Controller (MVC) |
@WebMvcTest |
Medium |
API contracts, auth |
| Repository (R2DBC) |
@DataR2dbcTest |
Medium |
DB queries |
| Repository (JPA) |
@DataJpaTest |
Medium |
JPA queries |
| Blackbox |
@SpringBootTest(DEFINED_PORT) + @Testcontainers |
Slow |
Full-stack JSON-driven |
| E2E |
@SpringBootTest + @Testcontainers |
Slow |
Full flows |
Ratio: unit > integration > E2E. Min coverage: 80% line (JaCoCo).
Verification Pipeline (7 Phases)
| Phase |
What |
Gate |
| 1. Compile |
Build sources + tests |
STOP on fail |
| 2. Unit Tests |
Fast tests |
STOP on fail |
| 3. Integration |
Testcontainers tests |
STOP on fail |
| 4. Coverage |
JaCoCo check |
BLOCK < 60% |
| 5. Security |
OWASP + secrets scan |
BLOCK CRITICAL |
| 6. Static Analysis |
.block(), @Autowired, debug stmts |
CRITICAL: .block() |
| 7. Diff Review |
Changed files review |
Manual |
Full commands per phase → references/verification-pipeline.md.
Quick Verification Modes
| Mode |
Phases |
Use Case |
quick |
1-2 |
During development |
standard |
1-4 |
Before committing |
full |
1-7 |
Before PR / release |
security |
5-6 |
Security-focused review |
Naming & Organization
- Test methods:
shouldDoXWhenY (e.g., shouldReturnOrderWhenIdExists)
- Files:
src/test/java/{unit,integration,e2e,blackbox}/
- Blackbox JSON:
src/test/resources/blackbox/test-cases/{app}/{domain}/
- Shared data:
TestDataFactory.java with builder methods (no random/hardcoded values)
Key Rules
- StepVerifier for all reactive assertions (never
Thread.sleep)
- Testcontainers with
.withReuse(true) for local speed
- No
@MockBean in blackbox tests — use WireMock stubs
- No H2 — always real DB via Testcontainers
@BeforeEach cleanup — independent tests, no shared state
- Test slices (
@WebMvcTest, @DataR2dbcTest) over @SpringBootTest for unit/slice tests
References
- references/tdd-patterns.md — Unit tests (JUnit 5 + Mockito + StepVerifier), WebFlux/MVC, R2DBC/JPA, Kafka, mocking, JaCoCo, common mistakes
- references/blackbox-test.md — JSON-driven test cases (F8A Summer Test), structure, JSON path assertions, WireMock stubs, template, file org
- references/verification-pipeline.md — 7-phase detail, commands, static analysis, diff review
Related Skills
- summer-test — Summer-specific Testcontainers, WireMock, blackbox test JSON format
- spring-webflux-patterns — StepVerifier (WebFlux) and MockMvc (MVC) test patterns
- database-patterns — @DataR2dbcTest, @DataJpaTest, Flyway migration testing
- coding-standards — Test naming conventions (shouldDoXWhenY)
1---2name: testing-workflow3description: Unified testing workflow — TDD (RED/GREEN/REFACTOR), blackbox integration testing with F8A Summer Test (JSON test cases, WireMock, Testcontainers), and 7-phase verification pipeline. Use when writing unit or integration tests, generating test scaffolds, configuring JaCoCo coverage thresholds, using StepVerifier for reactive tests, MockMvc/WebTestClient for API tests, or setting up Testcontainers. Includes scripts/generate-test-scaffold.sh.4---56# Testing Workflow78## TDD Cycle910**RED** — failing test. **GREEN** — minimal code to pass. **REFACTOR** — clean up, tests stay green.1112```java13// RED: write test first14@Test void shouldCreateOrderWhenValidInput() {15 StepVerifier.create(orderService.create(validCommand))16 .assertNext(o -> assertThat(o.getStatus()).isEqualTo(OrderStatus.PENDING))17 .verifyComplete();18}19// GREEN: ./gradlew test -> implement until pass20// REFACTOR: ./gradlew test jacocoTestReport -> clean up, verify coverage >= 80%21```2223## Test Pyramid2425| Type | Annotation | Speed | Use For |26|------|-----------|-------|---------|27| Unit | `@ExtendWith(MockitoExtension.class)` | Fast | Service/domain logic |28| Controller (WebFlux) | `@SpringBootTest + @AutoConfigureWebTestClient` | Medium | API contracts |29| Controller (MVC) | `@WebMvcTest` | Medium | API contracts, auth |30| Repository (R2DBC) | `@DataR2dbcTest` | Medium | DB queries |31| Repository (JPA) | `@DataJpaTest` | Medium | JPA queries |32| Blackbox | `@SpringBootTest(DEFINED_PORT) + @Testcontainers` | Slow | Full-stack JSON-driven |33| E2E | `@SpringBootTest + @Testcontainers` | Slow | Full flows |3435**Ratio:** unit > integration > E2E. Min coverage: **80% line** (JaCoCo).3637## Verification Pipeline (7 Phases)3839| Phase | What | Gate |40|-------|------|------|41| 1. Compile | Build sources + tests | STOP on fail |42| 2. Unit Tests | Fast tests | STOP on fail |43| 3. Integration | Testcontainers tests | STOP on fail |44| 4. Coverage | JaCoCo check | BLOCK < 60% |45| 5. Security | OWASP + secrets scan | BLOCK CRITICAL |46| 6. Static Analysis | .block(), @Autowired, debug stmts | CRITICAL: .block() |47| 7. Diff Review | Changed files review | Manual |4849Full commands per phase → `references/verification-pipeline.md`.5051## Quick Verification Modes5253| Mode | Phases | Use Case |54|------|--------|----------|55| `quick` | 1-2 | During development |56| `standard` | 1-4 | Before committing |57| `full` | 1-7 | Before PR / release |58| `security` | 5-6 | Security-focused review |5960## Naming & Organization6162- Test methods: `shouldDoXWhenY` (e.g., `shouldReturnOrderWhenIdExists`)63- Files: `src/test/java/{unit,integration,e2e,blackbox}/`64- Blackbox JSON: `src/test/resources/blackbox/test-cases/{app}/{domain}/`65- Shared data: `TestDataFactory.java` with builder methods (no random/hardcoded values)6667## Key Rules6869- **StepVerifier** for all reactive assertions (never `Thread.sleep`)70- **Testcontainers** with `.withReuse(true)` for local speed71- **No `@MockBean`** in blackbox tests — use WireMock stubs72- **No H2** — always real DB via Testcontainers73- **`@BeforeEach` cleanup** — independent tests, no shared state74- **Test slices** (`@WebMvcTest`, `@DataR2dbcTest`) over `@SpringBootTest` for unit/slice tests7576## References7778- **[references/tdd-patterns.md](references/tdd-patterns.md)** — Unit tests (JUnit 5 + Mockito + StepVerifier), WebFlux/MVC, R2DBC/JPA, Kafka, mocking, JaCoCo, common mistakes79- **[references/blackbox-test.md](references/blackbox-test.md)** — JSON-driven test cases (F8A Summer Test), structure, JSON path assertions, WireMock stubs, template, file org80- **[references/verification-pipeline.md](references/verification-pipeline.md)** — 7-phase detail, commands, static analysis, diff review8182## Related Skills8384- **summer-test** — Summer-specific Testcontainers, WireMock, blackbox test JSON format85- **spring-webflux-patterns** — StepVerifier (WebFlux) and MockMvc (MVC) test patterns86- **database-patterns** — @DataR2dbcTest, @DataJpaTest, Flyway migration testing87- **coding-standards** — Test naming conventions (shouldDoXWhenY)