如何让 cuke4duke 查找步骤定义
我已经使用 Maven 配置了 cuke4duke 和 Cucumber,并编写了功能和步骤定义文件。
我的功能文件位于 [ProjectDir]\features\example2.feature
Feature: Example of a feature file
As some aspiring cuke4duke user
I want an example of how it works
So that I can easily setup my project to use it
# This should pass
Scenario: A simple passing scenario
Given the letter 'A'
When I check the letter
Then the letter should be 'A'
我的步骤定义位于 [ProjectDir]\src\test\java\Example2Steps.java
package test.java;
import cuke4duke.annotation.I18n.EN.Given;
import cuke4duke.annotation.I18n.EN.Then;
import cuke4duke.annotation.I18n.EN.When;
import static org.junit.Assert.assertThat;
import static org.hamcrest.CoreMatchers.is;
public class Example2Steps {
private char theLetter;
@Given("^the letter 'A'$")
public void gimmeALetter(final char theLetter) {
this.theLetter = theLetter;
}
@When("^I check the letter$")
public void checkThem() {
// just a stub
}
@Then("^the letter should be 'A'$")
public void checkTheLetter(final char aLetter) {
assertThat(theLetter, is(aLetter));
}
}
当我在 Windows 命令提示符中的项目目录中运行“mvn Integration-test”时它构建得很好,但告诉我场景和步骤未定义。
输出:
[INFO] [cuke4duke:cucumber {execution: run-features}]
[INFO] Feature: Example of a feature file
[INFO] As some aspiring cuke4duke user
[INFO] I want an example of how it works
[INFO] So that I can easily setup my project to use it
[INFO]
[INFO] # This should pass
[INFO] Scenario: A simple passing scenario # features\example2.feature:7
[INFO] Given the letter 'A' # features\example2.feature:8
[INFO] When I check the letter # features\example2.feature:9
[INFO] Then the letter should be 'A' # features\example2.feature:10
[INFO]
[INFO] 1 scenario (1 undefined)
[INFO] 3 steps (3 undefined)
[INFO] 0m0.053s
[INFO]
[INFO] You can implement step definitions for undefined steps with these snippets:
[INFO]
[INFO] Given /^the letter 'A'$/ do
[INFO] pending # express the regexp above with the code you wish you had
[INFO] end
[INFO]
[INFO] When /^I check the letter$/ do
[INFO] pending # express the regexp above with the code you wish you had
[INFO] end
[INFO]
[INFO] Then /^the letter should be 'A'$/ do
[INFO] pending # express the regexp above with the code you wish you had
[INFO] end
[INFO]
[INFO] If you want snippets in a different programming language, just make sure a file
[INFO] with the appropriate file extension exists where cucumber looks for step definitions.
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
据我在任何地方读到的内容,cuke4duke 在 [ProjectDir]\src\test\java\ 中查找步骤定义,为什么它找不到我的定义?
I have configured cuke4duke and Cucumber with maven and written feature and step definition files.
My feature file is located at [ProjectDir]\features\example2.feature
Feature: Example of a feature file
As some aspiring cuke4duke user
I want an example of how it works
So that I can easily setup my project to use it
# This should pass
Scenario: A simple passing scenario
Given the letter 'A'
When I check the letter
Then the letter should be 'A'
My step definitions are located at [ProjectDir]\src\test\java\Example2Steps.java
package test.java;
import cuke4duke.annotation.I18n.EN.Given;
import cuke4duke.annotation.I18n.EN.Then;
import cuke4duke.annotation.I18n.EN.When;
import static org.junit.Assert.assertThat;
import static org.hamcrest.CoreMatchers.is;
public class Example2Steps {
private char theLetter;
@Given("^the letter 'A'$")
public void gimmeALetter(final char theLetter) {
this.theLetter = theLetter;
}
@When("^I check the letter$")
public void checkThem() {
// just a stub
}
@Then("^the letter should be 'A'$")
public void checkTheLetter(final char aLetter) {
assertThat(theLetter, is(aLetter));
}
}
When I run "mvn integration-test" at project dir in Windows command prompt it builds fine, but tells me that the scenario and steps are undefined.
Output:
[INFO] [cuke4duke:cucumber {execution: run-features}]
[INFO] Feature: Example of a feature file
[INFO] As some aspiring cuke4duke user
[INFO] I want an example of how it works
[INFO] So that I can easily setup my project to use it
[INFO]
[INFO] # This should pass
[INFO] Scenario: A simple passing scenario # features\example2.feature:7
[INFO] Given the letter 'A' # features\example2.feature:8
[INFO] When I check the letter # features\example2.feature:9
[INFO] Then the letter should be 'A' # features\example2.feature:10
[INFO]
[INFO] 1 scenario (1 undefined)
[INFO] 3 steps (3 undefined)
[INFO] 0m0.053s
[INFO]
[INFO] You can implement step definitions for undefined steps with these snippets:
[INFO]
[INFO] Given /^the letter 'A'$/ do
[INFO] pending # express the regexp above with the code you wish you had
[INFO] end
[INFO]
[INFO] When /^I check the letter$/ do
[INFO] pending # express the regexp above with the code you wish you had
[INFO] end
[INFO]
[INFO] Then /^the letter should be 'A'$/ do
[INFO] pending # express the regexp above with the code you wish you had
[INFO] end
[INFO]
[INFO] If you want snippets in a different programming language, just make sure a file
[INFO] with the appropriate file extension exists where cucumber looks for step definitions.
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
As far as I can read anywhere, cuke4duke looks for step definitions at [ProjectDir]\src\test\java\, why can't it find my definitions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后是我的一些 Maven pom 标签的大小写错误导致了错误。
我用以下内容交叉检查了我的 pom 和其他项目文件
示例项目,现在一切正常了!
https://github.com/jamesladd/maven-cuke4duke-jump-start
In the end it was wrong case in some of my Maven pom tags that caused the error.
I cross-checked my pom and other project files with the following
example project, and now it all works!
https://github.com/jamesladd/maven-cuke4duke-jump-start