Java 黄瓜JVM未定义的步骤
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21753267/
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
Cucumber JVM undefined step
提问by Thibault
I can't execute a simple test with cucumber for a project. I am on Intellij 13 Community, with cucumber plugin.
我无法用黄瓜为一个项目执行简单的测试。我在 Intellij 13 社区,带有黄瓜插件。
I wrote my feature file in my features directory, I have also implemented my steps, creating them with the help of the plugin. And my steps in the feature files are recognized by intellij, which can navigate and go to the step implementation.
我在我的 features 目录中编写了我的功能文件,我还实现了我的步骤,在插件的帮助下创建它们。并且我在特征文件中的步骤被intellij识别,可以导航到步骤实现。
But when I try to run my scenario, it always fails because for each step, it says "Undefined step : ".
但是当我尝试运行我的场景时,它总是失败,因为对于每个步骤,它都显示“未定义的步骤:”。
Here is how is organized my project :
这是我的项目的组织方式:
And as I said before, you can see that my steps are recognized by Intellij :
正如我之前所说,您可以看到我的步骤被 Intellij 识别:
How is that possible, and how can I correct this?
这怎么可能,我该如何纠正?
Any help would be great!
任何帮助都会很棒!
编辑Now that I added options to my runner :
现在我为我的跑步者添加了选项:
@CucumberOptions( monochrome = true,
features = "src/test/resources/features/",
format = { "pretty","html: cucumber-html-reports",
"json: cucumber-html-reports/cucumber.json" },
dryRun = false,
glue = "fr.tlasnier.cucumber" )
It works!
有用!
Yet, I noticed that before that, I had two scenario outline. One worked perfectly, the other one could not find step definition!
然而,我注意到在此之前,我有两个场景大纲。一个工作完美,另一个找不到步骤定义!
Really weird, since there were some steps in both scenario.
真的很奇怪,因为在这两种情况下都有一些步骤。
采纳答案by Bala
@RunWith(Cucumber.class)
@CucumberOptions( monochrome = true,
tags = "@tags",
features = "src/test/resources/features/",
format = { "pretty","html: cucumber-html-reports",
"json: cucumber-html-reports/cucumber.json" },
dryRun = false,
glue = "fr.tlasnier.cucumber" )
public class RunCucumber_Test {
//Run this
}
回答by david euler
I've met the same problem. And found that if the package where step definitions exists has not been created in the corresponding source folder. You can try to create a class under fr.tlasnier.cucumber.step, then idea should be able to find the steps. I think it is a bug in Idea.
我遇到了同样的问题。并发现如果对应的源文件夹中没有创建步骤定义所在的包。可以尝试在fr.tlasnier.cucumber.step下创建一个类,idea应该可以找到步骤。我认为这是Idea中的一个错误。
回答by Vel Ganesh
The class in which the steps are defined should be public. Anything else would throw the undefined step error.
定义步骤的类应该是公共的。其他任何事情都会引发未定义的步骤错误。