Java 黄瓜:如何从功能文件运行特定场景

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40945130/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 23:01:36  来源:igfitidea点击:

cucumber: how to run specific scenario from a feature file

javacucumber

提问by Aditya

I have multiple scenarios listed in a feature file and I need to run only a single failing scenario (for debugging purposes).

我在一个特性文件中列出了多个场景,我只需要运行一个失败的场景(用于调试目的)。

I have mentioned @tag before the scenario but while in Test Runner file when given this tag it is running entire feature file. Please help me out how to put it correctly.

我在场景之前提到了@tag,但是在 Test Runner 文件中,当给定这个标签时,它正在运行整个功能文件。请帮助我如何正确放置它。

TEST Runner file -

TEST Runner 文件 -

tags={"@Islamic_User_check"},

采纳答案by JohnP2

Update: there is now a tags options

更新:现在有一个标签选项

cucumber --tags @tagname

In maven:

在 Maven 中:

 mvn test -Dcucumber.options="--tags @tagname"

(and in Windows powershell escape the -D with a backtick)

(在 Windows powershell 中用反引号转义 -D)

 mvn test `-Dcucumber.options="--tags @tagname"

回答by Runningriot

If you want to run a specific scenario using cucumber you need to provide the line number the scenario starts on like:

如果要使用黄瓜运行特定场景,则需要提供场景开始的行号,例如:

cucumber features/test.feature:7

if you use the @ feature it should point to a txt file where the line number is still given.

如果您使用 @ 功能,它应该指向一个仍然给出行号的 txt 文件。

Source: https://www.relishapp.com/cucumber/cucumber/docs/cli/run-specific-scenarios

来源:https: //www.relishapp.com/cucumber/cucumber/docs/cli/run-specific-scenarios

Hope this helps

希望这可以帮助

回答by Aweston

Use the --name REGEXPcommand line argument to run only the scenarios that match the regular expression REGEXP:

使用--name REGEXP命令行参数仅运行与正则表达式 REGEXP 匹配的场景:

cucumber --name "Islamic_User_check"

回答by javaPlease42

If you use IntelliJthen I suggest installing the Cucumber for Java plugin.

如果您使用IntelliJ,那么我建议安装 Cucumber for Java 插件。

enter image description here

在此处输入图片说明

Then you can right-click on the Testannotation in the featurefile and run that single test scenario.

然后,您可以右键单击文件中的Test注释feature并运行该单个测试场景。

enter image description here

在此处输入图片说明