Maven + Cucumber-jvm - 如何根据环境 运行 不同的功能子集

Maven + Cucumber-jvm - How to run different subset of the features depending on environment

我正在努力实现这一目标:我想配置一个 Maven 项目,以便它 运行 根据 selected 配置文件 (dev | pro) 运行s 黄瓜功能的不同子集

例如,我有几个功能文件来测试网络导航,使用标签指定环境:

PRO

@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 类,每个环境一个:

共同基础CLASS:

@Test(groups="cucumber")
@CucumberOptions(format = "pretty")
public class AbstractBddTest extends AbstractTestNGCucumberTests {

PRO

@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 时,显然 运行 是两个测试类,并且每个类都会测试其对应的标记特征。我如何 select 使用配置文件的标签,以便只有一个测试 类 执行?

最终,我想出了如何在使用配置文件时将标签配置传递给黄瓜:

<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 来根据环境限制我想要 运行 的 scenarios/features。