简体   繁体   English

Dcucumber.options,运行单个黄瓜测试

[英]Dcucumber.options, run a single cucumber test

I have to following project structure:我必须遵循项目结构:

The directory src/test/java/ic/tests contains junit tests and the directory src/test/features/ic contains cucumber test (feature files).目录src/test/java/ic/tests包含 junit 测试,目录src/test/features/ic包含黄瓜测试(功能文件)。

But when I do a maven run ( mvn test -Dcucumber.options="src/test/features/ic --tags @IC-115 ") to execute a single cucumber test the executor starts the junit tests in the src/test/java/ic/tests directory...但是当我执行 maven 运行( mvn test -Dcucumber.options="src/test/features/ic --tags @IC-115 ")来执行单个黄瓜测试时,执行程序会在src/test/ 中启动 junit 测试java/ic/tests目录...

Only the corresponding feature file is annotated with @IC-115 .只有相应的特征文件被@IC-115注释。

Even the absolute version mvn test -Dcucumber.options="C:\\Users_Clemens_\\Documents\\test-ic\\src\\test\\resources\\features\\ic\\IC-115-LogOut.feature" does not execute my test.即使绝对版本mvn test -Dcucumber.options="C:\\Users_Clemens_\\Documents\\test-ic\\src\\test\\resources\\features\\ic\\IC-115-LogOut.feature"也不会执行我的测试。

How can I execute the single cucumber test that I want to execute?如何执行我想执行的单个黄瓜测试?

在此处输入图片说明

在此处输入图片说明

Try to run the command with the name of the feature (exact way to the feature).尝试使用功能名称运行命令(功能的确切方式)。

mvn test -Dcucumber.options="src/test/features/ic/FeatureName.feature" mvn test -Dcucumber.options="src/test/features/ic/FeatureName.feature"

Or if the feature is composed by more than one test you could set a specific(not used for others scenarios) tag to the test and run with或者,如果该功能由多个测试组成,您可以为测试设置一个特定的(不用于其他场景)标签并运行

mvn verify -Dcucumber.options="--tags @specifictag"

Could solve it by adding a runner class AND moved feature files to "src/test/resources" AND added the maven-surefire-plugin with adding an exclusion to the runner class.可以通过添加 runner 类并将特征文件移动到“src/test/resources”并添加 maven-surefire-plugin 并为 runner 类添加排除来解决它。 Seems like these 3 steps are all necessary.好像这三个步骤都是必要的。

package kiwigrid;

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(features="src/test/resources")
public class Runner {

}

在此处输入图片说明

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

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