Springboot Tdd
Test-driven development for Spring Boot using JUnit 5, Mockito, MockMvc, Testcontainers, and JaCoCo. Use when adding features, fixing bugs, or refactoring.
Get the complete skill folder, including its scripts and reference files.
·
When to use this skill
Use Springboot Tdd when an AI agent needs a reusable SKILL.md workflow for this job: Test-driven development for Spring Boot using JUnit 5, Mockito, MockMvc, Testcontainers, and JaCoCo. Use when adding features, fixing bugs, or refactoring.
When not to use it
Skip Springboot Tdd when the task is outside the coding category, or when a more specific skill in this directory already covers the same workflow with clearer triggers.
How to install
Where will you use it?
mkdir -p ~/.claude/skills/springboot-tdd # Save SKILL.md to ~/.claude/skills/springboot-tdd/SKILL.md
- Claude Code personal install: place the skill and its bundled files at ~/.claude/skills/springboot-tdd/SKILL.md. For a shared project, commit the folder at .claude/skills/springboot-tdd/ instead.
- Current Claude Code detects SKILL.md changes in watched directories during the session. If you just created a top-level skills directory, run /reload-skills. Check that the skill is listed before testing its trigger.
- For Claude chat or Cowork in the Desktop app, manage uploaded skills in Customize > Skills; copying files into a local Claude Code folder is not a Desktop install. Other agents may use different install locations.
Full install guide for Claude, Cursor, and Codex →
Try a starter prompt
After installing the skill, paste this starter prompt into your agent to verify it triggers on a small task.
Use the Springboot Tdd skill for this task: New features or endpoints. Confirm any required inputs or files before making changes.
What supports this recommendation?
83/100 provisional content score. This measures documentation, practical detail and source signals. It is not a measured task success rate or a security certification.
- Documentation
- 91/100
- Practical detail
- 92/100
- Source evidence
- 63/100
- Source signals
- 70/100
Model compatibility evidence
- claudeuntested
No model-specific signal or recorded compatibility test was found.
- chatgptuntested
No model-specific signal or recorded compatibility test was found.
- geminiuntested
No model-specific signal or recorded compatibility test was found.
- copilotuntested
No model-specific signal or recorded compatibility test was found.
- llamauntested
No model-specific signal or recorded compatibility test was found.
- perplexityuntested
No model-specific signal or recorded compatibility test was found.
- mistraluntested
No model-specific signal or recorded compatibility test was found.
- grokuntested
No model-specific signal or recorded compatibility test was found.
Inferred compatibility is based on content signals. Check the app, its available tools and setup requirements before running a skill.
What this skill does
# Spring Boot TDD Workflow
TDD guidance for Spring Boot services with 80%+ coverage (unit + integration).
## When to Use
- New features or endpoints - Bug fixes or refactors - Adding data access logic or security rules
## Workflow
1) Write tests first (they should fail) 2) Implement minimal code to pass 3) Refactor with tests green 4) Enforce coverage (JaCoCo)
## Unit Tests (JUnit 5 + Mockito)
```java @ExtendWith(MockitoExtension.class) class MarketServiceTest { @Mock MarketRepository repo; @InjectMocks MarketService service;
@Test void createsMarket() { CreateMarketRequest req = new CreateMarketRequest("name", "desc", Instant.now(), List.of("cat")); when(repo.save(any())).thenAnswer(inv -> inv.getArgument(0));
Market result = service.create(req);
assertThat(result.name()).isEqualTo("name"); verify(repo).save(any()); } } ```
Patterns: - Arrange-Act-Assert - Avoid partial mocks; prefer explicit stubbing - Use `@ParameterizedTest` for variants
## Web Layer Tests (MockMvc)
```java @WebMvcTest(MarketController.class) class MarketControllerTest { @Autowired MockMvc mockMvc; @MockBean MarketService marketService;
@Test void returnsMarkets() throws Exception { when(marketService.list(any())).thenReturn(Page.empty());
mockMvc.perform(get("/api/markets")) .andExpect(status().isOk()) .andExpect(jsonPath("$.content").isArray()); } } ```
## Integration Tests (SpringBootTest)
```java @SpringBootTest @AutoConfigureMockMvc @ActiveProfiles("test") class MarketIntegrationTest { @Autowired MockMvc mockMvc;
@Test void createsMarket() throws Exception { mockMvc.perform(post("/api/markets") .contentType(MediaType.APPLICATION_JSON) .content(""" {"name":"Test","description":"Desc","endDate":"2030-01-01T00:00:00Z","categories":["general"]} """)) .andExpect(status().isCreated()); } } ```
## Persistence Tests (DataJpaTest)
```java @DataJpaTest @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) @Import(TestContainersConfig.class) class MarketRepositoryTest { @Autowired MarketRepository repo;
@Test void savesAndFinds() { MarketEntity entity = new MarketEntity(); entity.setName("Test"); repo.save(entity);
Optional<MarketEntity> found = repo.findByName("Test"); assertThat(found).isPresent(); } } ```
## Testcontainers
- Use reusable containers for Postgres/Redis to mirror production - Wire via `@DynamicPropertySource` to inject JDBC URLs into Spring context
## Coverage (JaCoCo)
Maven snippet: ```xml <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.14</version> <executions> <execution> <goals><goal>prepare-agent</goal></goals> </execution> <execution> <id>report</id> <phase>verify</phase> <goals><goal>report</goal></goals> </execution> </executions> </plugin> ```
## Assertions
- Prefer AssertJ (`assertThat`) for readability - For JSON responses, use `jsonPath` - For exceptions: `assertThatThrownBy(...)`
## Test Data Builders
```java class MarketBuilder { private String name = "Test"; MarketBuilder withName(String name) { this.name = name; return this; } Market build() { return new Market(null, name, MarketStatus.ACTIVE); } } ```
## CI Commands
- Maven: `mvn -T 4 test` or `mvn verify` - Gradle: `./gradlew test jacocoTestReport`
**Remember**: Keep tests fast, isolated, and deterministic. Test behavior, not implementation details.
Intended uses
- New features or endpoints
- Bug fixes or refactors
- Adding data access logic or security rules
- Write tests first (they should fail)
- Implement minimal code to pass
- Refactor with tests green
- Enforce coverage (JaCoCo)
Implementation notes
- Review the source instructions and adapt inputs before running the workflow.
Try it, then tell us how it went
A copied prompt does not tell us whether the task worked. Report your result after checking the output. We collect your tool and outcome, never your files or prompt.