[英]Cannot execute maven test from command line using tags?
當我運行以下命令時:
mvn test -Dcucumber.options =“-tags @UserAuthentication”
然后我得到以下錯誤:
Unknown lifecycle phase
".options=src/test/java/Feature --tags @@UserAuthentication".
You must specify a valid lifecycle phase or a goal in the format
<plugin-prefix>:<goal> or
<plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>
我的POM文件如下:
http://maven.apache.org/xsd/maven-4.0.0.xsd“> 4.0.0 com.test.org測試0.0.1-SNAPSHOT
<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties> <build> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>3.0.0-M3</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> </plugin> </plugins> </pluginManagement> </build> <dependencies> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>3.7.1</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> <dependency> <groupId>info.cukes</groupId> <artifactId>cucumber-java</artifactId> <version>1.2.5</version> </dependency> <dependency> <groupId>info.cukes</groupId> <artifactId>cucumber-jvm-deps</artifactId> <version>1.0.5</version> <scope>provided</scope> </dependency> <dependency> <groupId>info.cukes</groupId> <artifactId>cucumber-junit</artifactId> <version>1.2.5</version> <scope>test</scope> </dependency> <dependency> <groupId>com.vimalselvam</groupId> <artifactId>cucumber-extentsreport</artifactId> <version>3.0.2</version> </dependency> <dependency> <groupId>com.aventstack</groupId> <artifactId>extentreports</artifactId> <version>3.1.2</version> </dependency> </dependencies> </project>
我的跑步者類如下:
@RunWith(Cucumber.class)
@CucumberOptions(
features ="src/test/java/Feature",
glue= "stepDefinitions",
tags= {"@Pagination,@UserAuthentication"},
plugin = { "com.cucumber.listener.ExtentCucumberFormatter:target/cucumber-reports/report.html"},
monochrome = true)
public class RunnerTest {
@AfterClass
public static void writeExtentReport() {
Reporter.loadXMLConfig(new File("config/report.xml"));
}
}
我不知道要使用標記從命令行運行測試的目標是什么。
根據https://maven.apache.org/surefire/maven-surefire-plugin/examples/system-properties.html ,有兩種方法可以將“系統屬性”傳遞給surefire(MVN測試)執行:
configuration/systemPropertyVariables
configuration/systemProperties
元素。 您沒有使用這些。
另請注意,只能以這種方式傳遞“字符串類型”屬性。 ...和:
必須在派生VM的命令行上設置某些系統屬性,並且在啟動VM之后不能設置某些系統屬性。 這些屬性必須添加到Surefire插件的argLine參數中。 例如,
<argLine>-Djava.endorsed.dirs=...</argLine>
因此,在您的情況下,最安全的方法(假定執行分叉的方法)是:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<argLine>-Dcucumber.options="--tags @UserAuthentication"</argLine>
</configuration>
</plugin>
...也可能:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<systemPropertyVariables>
<cucumber.options>--tags @UserAuthentication</cucumber.options>
</systemPropertyVariables>
</configuration>
</plugin>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.