java - 使用 cucumber-spring 合并属性文件
问题描述
我们正在使用 cucumber + selenium 来促进 e2e 测试。我们正在使用以下依赖项来利用 spring 依赖项注入。
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-spring</artifactId>
<version>6.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.6.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.2.6.RELEASE</version>
<scope>provided</scope>
</dependency>
然后我们使用这两个类来配置spring context
@ContextConfiguration(classes = SpringContextConfig.class)
@CucumberContextConfiguration
public class CucumberSpringConfiguration {
}
@PropertySource("application.properties")
@ComponentScan("com.example.e2e")
public class SpringContextConfig {
}
正如我们所看到的,我们的属性源被明确定义为指向给定的文件。有没有办法实现 Spring Boot 对配置文件和属性文件所做的“魔术”?
例如,当指定-Dspring.profiles.active=dev
合并
application-dev.properties
并application.properties
给出最终的上下文属性时,我会期待春天。
解决方案
正如我们所看到的,我们的属性源被明确定义为指向给定的文件。有没有办法实现 Spring Boot 对配置文件和属性文件所做的“魔术”?
Profile 特定的配置文件是 Spring Boot 的一项功能。因此,如果您使用的是 Spring boot,这应该足以让活动配置文件被拾取:
@SpringBootTest
@CucumberContextConfiguration
public class CucumberSpringConfiguration {
}
但是,从您的依赖项来看,您似乎没有使用 Spring Boot。没有其他(简单的)方法可以使用配置文件特定的配置文件。考虑使您的应用程序成为 Spring Boot 应用程序。
推荐阅读
- ruby - 我怎么能干这个while循环?
- javascript - 如何使用纯 js 向 DOM 插入和执行脚本标签
- google-analytics - iframe 和父页面都被 GA 跟踪
- android - 在 Android 上测量 OpenCl 使用的内存
- jupyter-notebook - 无法加载 jython 内核
- machine-learning - 用 gensim 的 fasttext 的 wrapper 训练词嵌入后,如何嵌入新句子?
- powershell - 更改 Windows Powershell 脚本标题
- reactjs - ReactJS - 我的掷骰子结果不会显示?
- angular - Angular TS SourceMaps 在 Chrome 调试器中不起作用
- node.js - 安装包未显示在我的 package.json 文件中