我们正在使用黄瓜+硒来促进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上下文。
@ContextConfiguration(classes = SpringContextConfig.class)
@CucumberContextConfiguration
public class CucumberSpringConfiguration {
}@PropertySource("application.properties")
@ComponentScan("com.example.e2e")
public class SpringContextConfig {
}由于我们可以选择属性源,因此可以显式地定义指向给定文件的属性源。有办法实现Spring对配置文件和属性文件所做的“魔力”吗?
例如,当指定-Dspring.profiles.active=dev将application-dev.properties与application.properties合并并给出最终的上下文属性时,我希望使用spring。
发布于 2021-03-12 16:52:44
由于我们可以选择属性源,因此可以显式地定义指向给定文件的属性源。有没有一种方法可以实现Spring对配置文件和属性文件所做的“魔力”?
配置文件特定的配置文件是Spring特性。因此,如果您使用的是Spring引导,那么这应该足以获取活动概要文件:
@SpringBootTest
@CucumberContextConfiguration
public class CucumberSpringConfiguration {
}但是,从您的依赖项来看,它看起来不像是在使用Spring。没有其他(容易)的方法来使用配置文件的配置文件。考虑让应用程序成为Spring应用程序。
https://stackoverflow.com/questions/66597037
复制相似问题