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

标签 maven testing cucumber bdd cucumber-jvm

我正在努力实现这一目标:我想配置一个 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/

相关文章:

cucumber - 如何让 Cucumber/guard 过滤 @wip 等标签?

eclipse - JBoss 7.1 与 Hibernate 4.3.5

python - 在 testinfra 中使用 Ansible 变量

performance - c++,cin 有问题吗?

ruby - cucumber 步骤定义正则表达式排除

java - 如何在没有任何功能文件的情况下运行 Cucumber?

maven - 使用 Cobertura 和 Jacoco 运行代码覆盖率

java - 当我使用 cloudera-manager-api 时,org.apache.cxf.jaxrs.client.AbstractClient.setupOutInterceptorChain 出现 NullPointerException

java - 无效或损坏的 jarFile

c++ - 在测试中检查对象的类型是公认的做法吗?