本规范基于项目现有代码实现,定义了单元测试和集成测试的设计原则和标准。项目目前尚未编写测试代码,本规范为未来测试开发提供指导。
pom.xml 中 未 包含常用的测试依赖(如 spring-boot-starter-test/junit-jupiter/mockito)。因此仓库内 src/test/java 目录目前为空。建议在 pom.xml 中添加以下依赖以开启测试能力:
<!-- Spring Boot Test(包含 JUnit 5、AssertJ、Mockito 等) -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- 可选:单独声明 JUnit Jupiter(若不使用 starter) -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.9.2</version>
<scope>test</scope>
</dependency>
<!-- 可选:Jacoco 用于覆盖率报告(在 CI 中使用插件方式更常见) -->
<!-- 在 pom.xml 中添加 jacoco-maven-plugin 的 build 插件配置 -->
添加这些依赖后,建议在本地或 CI 中运行 mvn test 并生成 coverage 报告(如使用 JaCoCo)。
UserServiceTest。should_When_Then 或 test_方法名_场景 格式。src/test/java 目录下,与主代码保持相同的包结构。mvn test 运行所有测试。