Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在单元测试中具有spring上下文_Java_Spring_Junit_Integration Testing_Spring Test - Fatal编程技术网

Java 在单元测试中具有spring上下文

Java 在单元测试中具有spring上下文,java,spring,junit,integration-testing,spring-test,Java,Spring,Junit,Integration Testing,Spring Test,我想将junit与spring上下文一起使用,以便编写一些集成测试 这些测试只需对rest端点执行一系列调用并断言响应。有些人认为这与所描述的内容相似,但使用了spring上下文,以便在单元测试中获得所需的内容(如resttemplate和用户创建服务)。为了不为每次运行实例化上下文,我将使用如下内容: @ContextConfiguration(locations = {"classpath:test-context.xml"}) @RunWith(SpringJUnit4ClassRunne

我想将junit与spring上下文一起使用,以便编写一些集成测试

这些测试只需对rest端点执行一系列调用并断言响应。有些人认为这与所描述的内容相似,但使用了spring上下文,以便在单元测试中获得所需的内容(如resttemplate和用户创建服务)。为了不为每次运行实例化上下文,我将使用如下内容:

@ContextConfiguration(locations = {"classpath:test-context.xml"})
@RunWith(SpringJUnit4ClassRunner.class)

因为我的ContextConfiguration具有相同的上下文,所以在所有测试运行期间都将保持缓存状态。我正试图添加一个yaml,以使其具有不同的环境(UAT、prod),但到目前为止,我所尝试的一切都不起作用。有没有办法在上下文xml中导入YML?

您可以使用@TestPropertySource加载不同的属性/yaml文件

@TestPropertySource(locations="classpath:test.properties")


看起来这个的副本不起作用;以不填充@Value字段的方式;如果我将yaml移出类路径,那么它在启动时会失败