我正在努力实现这一目标:我想配置一个 Maven 项目,以便它根据所选配置文件 (dev | pro) 运行不同的 cucumber 功能子集
例如,我有几个功能文件来测试网络导航,使用标签来指定环境:
专业版
@pro
Feature: Nav Pro
Scenario: navigate to home
Given access /
Then it should be at the home page
开发
@dev
Feature: Nav Dev
Scenario: navigate to login and log user correctly
Given access /login
When the user enters xxxx yyyy
Then it should be logged
我创建了两个测试 java 类,每个类一个:
通用基类:
@Test(groups="cucumber")
@CucumberOptions(format = "pretty")
public class AbstractBddTest extends AbstractTestNGCucumberTests {
专业版
@Test(groups="cucumber")
@CucumberOptions(tags={"@pro", "~@dev"})
public class ProTest extends AbstractBddTest{}
开发
@Test(groups="cucumber")
@CucumberOptions(tags={"@dev", "~@pro"})
public class DevTest extends AbstractBddTest{}
Maven cfg 摘录:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<groups>${test-groups}</groups>
</configuration>
</plugin>
...
<properties>
<test-groups>unit,integration</test-groups>
</properties>
当我运行 mvn test -Dtest-groups=cucumber
时,它显然运行了两个测试类,并且每个都将测试其相应的标记功能。如何使用配置文件选择标记,以便只执行一个测试类?
最佳答案
最终,我想出了在使用配置文件时如何将标签配置传递给 cucumber :
<profiles>
<profile>
<id>environment_dev</id>
<activation>
<property>
<name>environment</name>
<value>dev</value>
</property>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<groups>${test-groups}</groups>
<systemPropertyVariables>
<cucumber.options>--tags @dev</cucumber.options>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
有了这个,我可以调用 mvn test -Dtest-groups=cucumber -Denvironment=dev
来限制我想根据环境运行的场景/功能。
关于Maven + Cucumber-jvm - 如何根据环境运行不同的功能子集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35863929/