test(api-interface): 添加测试依赖和集成测试基类

- 在 pom.xml 中添加 spring-boot-starter-test 依赖
- 创建 ApiInterfaceApplicationTests 集成测试基类
- 配置 SpringBootTest 和 ActiveProfiles 注解
- 提供集成测试使用的上下文加载功能
- 添加详细的 JavaDoc 说明和使用示例
This commit is contained in:
zhengli 2026-05-25 18:21:10 +08:00
parent c3a7c8473b
commit d3689457cc
2 changed files with 42 additions and 0 deletions

View File

@ -24,6 +24,12 @@
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

View File

@ -0,0 +1,36 @@
package com;
import com.heyu.api.ApiUserApiApplication;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
/**
* 集成测试基类
* <p>
* 所有集成测试继承此类自动加载 Spring 上下文和 dev 环境配置
* 子类可直接 @Autowired 注入需要测试的 Service Mapper
* <p>
* 使用方式:
* <pre>
* &#64;SpringBootTest(classes = ApiUserApiApplication.class)
* class MyServiceTest extends ApiInterfaceApplicationTests {
* &#64;Autowired
* private MyService myService;
*
* &#64;Test
* void myTest() {
* // ...
* }
* }
* </pre>
*/
@SpringBootTest(classes = ApiUserApiApplication.class)
@ActiveProfiles("dev")
public class ApiInterfaceApplicationTests {
@Test
void contextLoads() {
}
}