Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.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
SpringBoot使用TestSuite和不同的属性文件在多个数据库上集成测试_Spring_Unit Testing_Jpa_Spring Boot_Integration Testing - Fatal编程技术网

SpringBoot使用TestSuite和不同的属性文件在多个数据库上集成测试

SpringBoot使用TestSuite和不同的属性文件在多个数据库上集成测试,spring,unit-testing,jpa,spring-boot,integration-testing,Spring,Unit Testing,Jpa,Spring Boot,Integration Testing,因此,我正在使用JPA并基于Oracle数据库开发SpringRESTAPI 我有一些集成测试,它们使用Derby(嵌入式db)。src/test/resource中有一个不同的application.properties文件,其中包含derby详细信息以实现这一点 我的项目中没有XML,除此之外,在配置方面没有其他内容。(顺便说一句,我不是春季冠军) 我需要的是在Derby和oracle上运行集成测试(很快还会有第三个db) 我想说的是: 对于测试套件1,集成测试,运行所有这些测试 类首先使

因此,我正在使用JPA并基于Oracle数据库开发SpringRESTAPI

我有一些集成测试,它们使用Derby(嵌入式db)。src/test/resource中有一个不同的application.properties文件,其中包含derby详细信息以实现这一点

我的项目中没有XML,除此之外,在配置方面没有其他内容。(顺便说一句,我不是春季冠军)

我需要的是在Derby和oracle上运行集成测试(很快还会有第三个db)

我想说的是:

  • 对于测试套件1,集成测试,运行所有这些测试 类首先使用derby属性文件,然后使用oracle 属性文件
  • 测试套件2,典型的单元测试,只需使用derby即可
看起来像这样的东西:

@RunWith(Suite.class)
@TestPropertySource(
        locations = "/application_oracle.properties",
        locations = "/application_derby.properties"
    )
@Suite.SuiteClasses({
    //Integration 
    CustomerApiIntegrationTest.class,
    StoreApiIntegrationTest.class
})
public class IntegrationTestsSuite{

}

但它不起作用。这个TestPropertySource对于一个属性文件在testSuite级别似乎没有任何影响,更不用说了


提前感谢。

您最好的办法是对每个测试套件使用
@ActiveProfiles
,并引用不同的配置文件名称。由于概要文件是框架用于缓存上下文的键的一部分,因此它将为每个键创建单独的上下文

完成此操作后,您可以在
src/test/resources
中创建
应用程序xyz.properties
,其中
xyz
是您的配置文件的名称(
derby
oracle
或您喜欢的任何名称)

应用程序上的
@PropertySource
无效,Spring Boot默认从类路径的根目录加载
应用程序.properties

@RunWith(Suite.class)
@TestPropertySource(
        locations = "/application_oracle.properties",
        locations = "/application_derby.properties"
    )
@Suite.SuiteClasses({
    //Integration 
    CustomerApiIntegrationTest.class,
    StoreApiIntegrationTest.class
})
public class IntegrationTestsSuite{

}
@RunWith(Suite.class)
@TestPropertySource(
        locations = "/application_derby.properties"
    )
@Suite.SuiteClasses({
    SimpleCustomerTest.class,
    SimpleStorreTest.class
})
public class OtherTestsSuite{

}