繁体   English   中英

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

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

我想要实现这个目标:我想配置一个maven项目,以便根据所选的配置文件运行不同的黄瓜功能子集(dev | pro)

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

PRO

@pro
Feature: Nav Pro

  Scenario: navigate to home
    Given access /
    Then it should be at the home page

DEV

@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

我创建了两个Test java类,每个环境对应一个:

共同基础类:

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

PRO

@Test(groups="cucumber")
@CucumberOptions(tags={"@pro", "~@dev"})
public class ProTest extends AbstractBddTest{}

DEV

@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它显然会运行两个测试条款,并且每个都将测试其相应的标记功能。 如何使用配置文件选择标记,以便只执行其中一个测试类?

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

<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来限制我想要运行的场景/功能,具体取决于环境。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM