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