springboot-tdd
Skill43 starsChanged 10 months agoMITView on GitHub
使用 JUnit 5、Mockito、MockMvc、Testcontainers 和 JaCoCo 进行 Spring Boot 的测试驱动开发(TDD)。在添加功能、修复 Bug 或进行重构时使用。
15 other projects use a version of this, 13 of them edited.
Adopted by
Most recently taken up by
- templetongroup/radiantedited, first seen Sep 17, 2026
- SamuelNDCE/claude-super-skill-libraryedited, first seen Aug 1, 2026
- JunMystery/Agent-Guidance-Pythonedited, first seen Jul 21, 2026
- Lukasbrujula/claude-code-frameworkedited, first seen Jul 6, 2026
- minghaoZhangZ/shipkittheir own version, first seen May 21, 2026
- Jamkris/everything-gemini-codeedited, first seen Apr 27, 2026
Used with
Projects with it also use swift-protocol-di-testing, content-hash-cache-pattern and 10 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
InfopibeSkillswift-protocol-di-testing
Protocol-based dependency injection for testable Swift code — mock file system, network, and external APIs using focused protocols and Swift Testing.
Also in 7 projects that use this
InfopibeSkillcontent-hash-cache-pattern
Cache expensive file processing results using SHA-256 content hashes — path-independent, auto-invalidating, with service layer separation.
Also in 7 projects that use this
saxon-ySkillconfigure-ecc
Interactive installer for Everything Claude Code — guides users through selecting and installing skills and rules to user-level or project-level directories, verifies paths, and optionally optimizes installed files.
Also in 7 projects that use this
- +9 more from Infopibe
Other versions15 projects use a version of this.
Word for word · 0
None found.
Edited · 13
- xu-xiang/everything-claude-code-zh★ 2k78% same
- loulanyue/awesome-claude-notes★ 27254% same
- tpavanipradeep/everything-claude-code★ 13454% same
- templetongroup/radiant★ 11354% same
- Jamkris/everything-gemini-code★ 8754% same
- FaisalAlqarni/sp-ecc★ 954% same
- Infopibe/everything-claude-code★ 854% same
- Lukasbrujula/claude-code-framework★ 454% same
- JunMystery/Agent-Guidance-Python★ 254% same
- ashutoshrathi0909-oss/everything-claude-code★ 154% same
3 more not listed
Wrote their own version · 2
- peopleforrester/claude-dotfiles★ 3same name
- minghaoZhangZ/shipkit★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository30 other files it gives its agents.
- rules/agents.mdAGENTS.md
- examples/CLAUDE.mdCLAUDE.md
- oneskillSkill
- backend-patternsSkill
- clickhouse-ioSkill
- coding-standardsSkill
- continuous-learningSkill
- continuous-learning-v2Skill
- django-patternsSkill
- django-securitySkill
- django-tddSkill
- django-verificationSkill
- eval-harnessSkill
- frontend-patternsSkill
- golang-patternsSkill
- golang-testingSkill
- iterative-retrievalSkill
- java-coding-standardsSkill
- jpa-patternsSkill
- postgres-patternsSkill
- project-guidelines-exampleSkill
- python-patternsSkill
- python-testingSkill
- security-reviewSkill
- springboot-patternsSkill
- springboot-securitySkill
- springboot-verificationSkill
- strategic-compactSkill
- tdd-workflowSkill
- verification-loopSkill
The file
Files
Spring Boot 测试驱动开发(TDD)工作流
针对 Spring Boot 服务的 TDD 指南,要求 80% 以上的覆盖率(单元测试 + 集成测试)。
适用场景
- 开发新功能或端点(Endpoints)
- 修复 Bug 或进行代码重构
- 添加数据访问逻辑或安全规则
工作流
- 先写测试(测试应当失败)
- 实现最少量的代码以使测试通过
- 在测试通过(Green)的前提下进行重构
- 强制执行覆盖率检查(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(准备-执行-断言)
- 避免部分打桩(Partial Mocks);优先使用显式桩函数(Stubbing)
- 使用
@ParameterizedTest处理多种变体场景
Web 层测试(MockMvc)
@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)
@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)
@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
- 使用可重用的容器(如 Postgres/Redis)来模拟生产环境
- 通过
@DynamicPropertySource进行连接,将 JDBC URL 注入到 Spring 上下文中
覆盖率(JaCoCo)
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>断言(Assertions)
- 为了提高可读性,优先选择 AssertJ (
assertThat) - 对于 JSON 响应,使用
jsonPath - 对于异常测试:
assertThatThrownBy(...)
测试数据构建器(Test Data Builders)
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 命令
- Maven:
mvn -T 4 test或mvn verify - Gradle:
./gradlew test jacocoTestReport
记住:保持测试快速、隔离且具有确定性。测试的是行为,而非实现细节。
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

