diff --git a/src/test/java/com/jenkins/demo/JenkinsDemoApplicationTests.java b/src/test/java/com/jenkins/demo/JenkinsDemoApplicationTests.java index 00b4057..2139ddd 100644 --- a/src/test/java/com/jenkins/demo/JenkinsDemoApplicationTests.java +++ b/src/test/java/com/jenkins/demo/JenkinsDemoApplicationTests.java @@ -2,12 +2,14 @@ package com.jenkins.demo; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.TestPropertySource; /** * Jenkins Demo Application Tests */ @SpringBootTest +@ActiveProfiles("test") @TestPropertySource(locations = "classpath:application-test.properties") class JenkinsDemoApplicationTests { diff --git a/src/test/java/com/jenkins/demo/controller/HealthControllerTest.java b/src/test/java/com/jenkins/demo/controller/HealthControllerTest.java index f824fad..3dece5e 100644 --- a/src/test/java/com/jenkins/demo/controller/HealthControllerTest.java +++ b/src/test/java/com/jenkins/demo/controller/HealthControllerTest.java @@ -5,6 +5,7 @@ import org.junit.jupiter.api.DisplayName; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.http.MediaType; +import org.springframework.test.context.ActiveProfiles; import org.springframework.test.web.servlet.MockMvc; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; @@ -13,6 +14,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. /** * Health Controller Tests */ +@ActiveProfiles("test") @WebMvcTest(HealthController.class) class HealthControllerTest { diff --git a/src/test/java/com/jenkins/demo/controller/UserControllerTest.java b/src/test/java/com/jenkins/demo/controller/UserControllerTest.java index 4d90fef..43b7340 100644 --- a/src/test/java/com/jenkins/demo/controller/UserControllerTest.java +++ b/src/test/java/com/jenkins/demo/controller/UserControllerTest.java @@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; +import org.springframework.test.context.ActiveProfiles; import org.springframework.test.web.servlet.MockMvc; import java.util.Arrays; @@ -25,6 +26,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. * User Controller Integration Tests */ @WebMvcTest(UserController.class) +@ActiveProfiles("test") class UserControllerTest { @Autowired diff --git a/src/test/resources/application-test.properties b/src/test/resources/application-test.properties index e3cda0c..79c2083 100644 --- a/src/test/resources/application-test.properties +++ b/src/test/resources/application-test.properties @@ -1,4 +1,6 @@ # Test Configuration -spring.profiles.active=test +# 注意:不要在profile-specific文件中设置spring.profiles.active logging.level.com.jenkins.demo=DEBUG server.port=0 +spring.datasource.url=jdbc:h2:mem:testdb +spring.h2.console.enabled=false