test(api-interface): 添加测试依赖和集成测试基类
- 在 pom.xml 中添加 spring-boot-starter-test 依赖 - 创建 ApiInterfaceApplicationTests 集成测试基类 - 配置 SpringBootTest 和 ActiveProfiles 注解 - 提供集成测试使用的上下文加载功能 - 添加详细的 JavaDoc 说明和使用示例
This commit is contained in:
parent
c3a7c8473b
commit
d3689457cc
@ -24,6 +24,12 @@
|
|||||||
<version>2.3.0</version>
|
<version>2.3.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|||||||
@ -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>
|
||||||
|
* @SpringBootTest(classes = ApiUserApiApplication.class)
|
||||||
|
* class MyServiceTest extends ApiInterfaceApplicationTests {
|
||||||
|
* @Autowired
|
||||||
|
* private MyService myService;
|
||||||
|
*
|
||||||
|
* @Test
|
||||||
|
* void myTest() {
|
||||||
|
* // ...
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
@SpringBootTest(classes = ApiUserApiApplication.class)
|
||||||
|
@ActiveProfiles("dev")
|
||||||
|
public class ApiInterfaceApplicationTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void contextLoads() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user