使用cumberspring合并属性文件

d8tt03nd  于 2021-07-23  发布在  Java
关注(0)|答案(1)|浏览(749)

我们使用 cucumber + selenium 来促进e2e测试。我们使用以下依赖项来利用spring依赖项注入。

  1. <dependency>
  2. <groupId>io.cucumber</groupId>
  3. <artifactId>cucumber-spring</artifactId>
  4. <version>6.8.1</version>
  5. <scope>test</scope>
  6. </dependency>
  7. <dependency>
  8. <groupId>org.springframework</groupId>
  9. <artifactId>spring-context</artifactId>
  10. <version>5.2.6.RELEASE</version>
  11. <scope>test</scope>
  12. </dependency>
  13. <dependency>
  14. <groupId>org.springframework</groupId>
  15. <artifactId>spring-test</artifactId>
  16. <version>5.2.6.RELEASE</version>
  17. <scope>provided</scope>
  18. </dependency>

然后我们使用这两个类来配置spring上下文

  1. @ContextConfiguration(classes = SpringContextConfig.class)
  2. @CucumberContextConfiguration
  3. public class CucumberSpringConfiguration {
  4. }
  1. @PropertySource("application.properties")
  2. @ComponentScan("com.example.e2e")
  3. public class SpringContextConfig {
  4. }

正如我们所能看到的,我们明确地定义了指向给定文件的属性源。有没有一种方法可以实现springboot对概要文件和属性文件的“魔力”?
例如,在指定 -Dspring.profiles.active=dev 合并 application-dev.propertiesapplication.properties 并给出最终的上下文属性。

3gtaxfhh

3gtaxfhh1#

正如我们所能看到的,我们明确地定义了指向给定文件的属性源。有没有一种方法可以实现springboot对概要文件和属性文件的“魔力”?
特定于配置文件的配置文件是spring引导特性。因此,如果您使用的是spring boot,这应该足以获取活动配置文件:

  1. @SpringBootTest
  2. @CucumberContextConfiguration
  3. public class CucumberSpringConfiguration {
  4. }

然而,从你的依赖关系来看,它看起来不像你在使用springboot。没有其他(简单的)方法可以使用特定于概要文件的配置文件。考虑让您的应用程序成为spring引导应用程序。

相关问题