From d3689457cceacec09020a295a4f438a6bcb69829 Mon Sep 17 00:00:00 2001 From: zhengli Date: Mon, 25 May 2026 18:21:10 +0800 Subject: [PATCH] =?UTF-8?q?test(api-interface):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=BE=9D=E8=B5=96=E5=92=8C=E9=9B=86=E6=88=90?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=9F=BA=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 pom.xml 中添加 spring-boot-starter-test 依赖 - 创建 ApiInterfaceApplicationTests 集成测试基类 - 配置 SpringBootTest 和 ActiveProfiles 注解 - 提供集成测试使用的上下文加载功能 - 添加详细的 JavaDoc 说明和使用示例 --- api-web/api-interface/pom.xml | 6 ++++ .../com/ApiInterfaceApplicationTests.java | 36 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 api-web/api-interface/src/test/java/com/ApiInterfaceApplicationTests.java diff --git a/api-web/api-interface/pom.xml b/api-web/api-interface/pom.xml index 5c063d5..c5aeab6 100644 --- a/api-web/api-interface/pom.xml +++ b/api-web/api-interface/pom.xml @@ -24,6 +24,12 @@ 2.3.0 + + org.springframework.boot + spring-boot-starter-test + test + + diff --git a/api-web/api-interface/src/test/java/com/ApiInterfaceApplicationTests.java b/api-web/api-interface/src/test/java/com/ApiInterfaceApplicationTests.java new file mode 100644 index 0000000..7e5321a --- /dev/null +++ b/api-web/api-interface/src/test/java/com/ApiInterfaceApplicationTests.java @@ -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; + +/** + * 集成测试基类 + *

+ * 所有集成测试继承此类,自动加载 Spring 上下文和 dev 环境配置。 + * 子类可直接 @Autowired 注入需要测试的 Service 或 Mapper。 + *

+ * 使用方式: + *

+ * @SpringBootTest(classes = ApiUserApiApplication.class)
+ * class MyServiceTest extends ApiInterfaceApplicationTests {
+ *     @Autowired
+ *     private MyService myService;
+ *
+ *     @Test
+ *     void myTest() {
+ *         // ...
+ *     }
+ * }
+ * 
+ */ +@SpringBootTest(classes = ApiUserApiApplication.class) +@ActiveProfiles("dev") +public class ApiInterfaceApplicationTests { + + @Test + void contextLoads() { + } + +}