springboot-tdd
Master test-driven development for Spring Boot services targeting 80%+ code coverage. This skill covers the complete TDD cycle—writing failing tests first, implementing minimal code to pass, refactoring safely, and enforcing coverage with JaCoCo. Learn unit testing with JUnit 5 and Mockito, web layer testing with MockMvc, integration testing with SpringBootTest, and persistence layer testing with DataJpaTest and Testcontainers.
springboot-tdd teaches test-driven development for Spring Boot using JUnit 5, Mockito, and MockMvc with 80%+ coverage targets.
AI-generated summary based on this skill's SKILL.md
Install
xu-xiang/everything-claude-code-zh/springboot-tdd · repository language: JavaScript
git clone https://github.com/xu-xiang/everything-claude-code-zh
cp -r everything-claude-code-zh/skills/springboot-tdd ~/.claude/skills/springboot-tddnpx skillfed install xu-xiang/everything-claude-code-zh/springboot-tddFrequently asked questions
AI-generated answers based on this skill's SKILL.md and metadata
What is the springboot-tdd skill's core focus?
springboot-tdd teaches test-driven development for Spring Boot services targeting 80%+ code coverage. It covers the complete TDD cycle—writing failing tests first, implementing minimal code to pass, refactoring safely, and enforcing coverage with JaCoCo. You'll learn unit testing with JUnit 5 and Mockito, web layer testing with MockMvc, integration testing with SpringBootTest, and persistence layer testing with DataJpaTest and Testcontainers.
How do I learn spring boot test driven development junit 5?
springboot-tdd covers the full TDD workflow for Spring Boot with JUnit 5 as its primary testing framework. You'll master writing failing tests first, implementing minimal code to pass them, and refactoring safely. The skill emphasizes best practices for TDD workflow and includes parameterized tests, custom assertions with AssertJ, and test isolation to ensure deterministic, repeatable test suites.
How can springboot-tdd help with mockito mock mvc testing?
springboot-tdd teaches MockMvc for web layer testing and Mockito for mocking dependencies. You'll learn to mock Spring beans, isolate controllers from services, and verify interactions. The skill covers both unit-level mocking and integration-level testing patterns, helping you write fast, focused tests that validate API behavior without requiring a full application context.
What does springboot-tdd cover for code coverage enforcement?
springboot-tdd includes setting up and enforcing code coverage targets using JaCoCo. You'll configure JaCoCo as a Maven or Gradle plugin, define coverage thresholds targeting 80%+, and integrate coverage checks into your CI/CD pipeline. The skill teaches how to measure coverage across unit, integration, and end-to-end tests to ensure meaningful coverage metrics.
Can springboot-tdd help me test repositories and services?
Yes, springboot-tdd covers unit testing for repositories using DataJpaTest and Testcontainers for real database instances. You'll learn to test service layers with mocked repositories, write integration tests that validate end-to-end flows, and use the data builder pattern for test fixture creation. The skill ensures your persistence and business logic layers are thoroughly tested.
How does springboot-tdd support refactoring existing code safely?
springboot-tdd teaches how to refactor Spring Boot code safely by establishing comprehensive test coverage first. With a solid test suite in place, you can confidently refactor implementation details while verifying behavior remains unchanged. The skill emphasizes test-driven refactoring as a best practice for maintaining code quality and preventing regressions during improvements.
SKILL.md
rendered from the published skill — quoted content, verbatim
Spring Boot TDD 工作流
针对具有 80% 以上覆盖率(单元测试 + 集成测试)的 Spring Boot 服务的 TDD 指南。
适用场景
- 新功能或 API 端点开发
- Bug 修复或重构
- 添加数据访问逻辑或安全规则
工作流
1) 先写测试(测试应当失败) 2) 实现通过测试的最简代码 3) 在测试通过的情况下重构代码 4) 强制执行覆盖率检查 (JaCoCo)
单元测试 (JUnit 5 + Mockito)
@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());
}
}
模式:
- 准备-执行-断言 (Arrange-Act-Assert)
- 避免部分 Mock;优先使用显式打桩 (Stubbing)
- 使用 @ParameterizedTest 处理用例变体
Web 层测试 (MockMvc)
```java @WebMvcTest(MarketController.class) class MarketControllerTest { @Autowired MockMvc mockMvc; @MockBean MarketService marketService;
@Test void returnsMarkets() throws Exception {
(truncated - see the full file via the links below)
Read as markdown · JSON record · Browse the source repository
File tree — 1 file
skills/springboot-tdd/SKILL.md