我有一个非常基本的SpringBootTest,我正在尝试运行它(contextLoads())测试。
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
@SpringBootTest
@ActiveProfiles("test")
public class ApplicationTest {
@Test
void contextLoads() {
}
}
我在application-test.yml
下有一个配置文件src/test/resources/
,该配置文件带有一些我想用来测试应用程序的基本配置。但是,即使使用上面的简单测试,上下文也不会加载。我正在使用IntelliJ来运行测试-当我使用Maven运行单元测试时,该测试只是处于运行状态,但似乎冻结了上下文的加载。我唯一看到的是
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.3.1.RELEASE)
并显示“正在运行测试...”,它没有解决。我不确定这是怎么回事。我注意到,当我删除@ActiveProfiles
注释时,该测试无法运行并抛出异常Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class
,该异常看起来像是它试图加载我的实际配置文件,但无法,因为我没有不要设置我在配置文件中使用的环境变量。那么我如何才能让SpringBootTest进入application-test.yml
并继续进行测试?