fix: fix Spring Boot test configuration issues
This commit is contained in:
parent
7b8bd55554
commit
22d7087d1f
@ -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 {
|
||||
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user