[英]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.