Guides TDD workflow for Spring Boot services using JUnit 5, Mockito, MockMvc, Testcontainers, and JaCoCo. For new features, bug fixes, refactoring with 80%+ coverage.
How this skill is triggered — by the user, by Claude, or both
Slash command
/everything-claude-code:springboot-tddThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
针对 Spring Boot 服务的 TDD 指南,要求 80% 以上的覆盖率(单元测试 + 集成测试)。
针对 Spring Boot 服务的 TDD 指南,要求 80% 以上的覆盖率(单元测试 + 集成测试)。
@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());
}
}
模式:
@ParameterizedTest 处理多种变体场景@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());
}
}
@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());
}
}
@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();
}
}
@DynamicPropertySource 进行连接,将 JDBC URL 注入到 Spring 上下文中Maven 配置片段:
<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>
assertThat)jsonPathassertThatThrownBy(...)class MarketBuilder {
private String name = "Test";
MarketBuilder withName(String name) { this.name = name; return this; }
Market build() { return new Market(null, name, MarketStatus.ACTIVE); }
}
mvn -T 4 test 或 mvn verify./gradlew test jacocoTestReport记住:保持测试快速、隔离且具有确定性。测试的是行为,而非实现细节。
npx claudepluginhub codelably/harmony-claude-codeGuides Spring Boot TDD workflow with JUnit 5, Mockito, MockMvc, Testcontainers, and JaCoCo for 80%+ coverage in unit, web, integration, and persistence tests. Use for new features, bug fixes, refactoring.
Guides Spring Boot TDD with JUnit 5, Mockito, MockMvc, Testcontainers, and JaCoCo. Use when adding features, fixing bugs, or refactoring.
Provides Spring Boot testing patterns for unit (Mockito), slice (@DataJpaTest/@WebMvcTest), integration (@SpringBootTest), and Testcontainers-based tests with JUnit 5. Use when writing @Test methods, @MockBean mocks, or test suites.