这个问题困扰了我半天。我似乎找不到问题所在。基本上,我的工作区中有测试运行程序、功能文件和步骤文件。 java 文件位于同一个包中(即没有包)。
下面是我的TestRunner.java
import org.junit.Test;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(features = "test/resources/features", tags = { "~@Ignore" })
public class TestRunner {
@Test
public void feature() {
}
}
我的功能文件,helloWorld.feature
Feature: Simple Test Feature
Scenario: Run Scenario ONE
GIVEN step one
WHEN step two
THEN step three
和我的步骤文件CucumberJava.java
,
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
public class CucumberJava {
@Given("^step one$")
public void step_one() {
System.out.println("step one");
}
@When("step two")
public void step_two() {
System.out.println("step two");
}
@Then("^step three$")
public void step_three() {
System.out.println("step three");
}
}
当我作为 JUnit 执行 TestRunner.java
时,一切都会通过,但我在控制台中看到以下内容:
0 Scenarios
0 Steps
0m0.000s
为什么?事实上,当我从项目中删除 CucumberJava.java
时,我得到了完全相同的输出。我缺少什么?
我还尝试在 TestRunner.java
代码中设置 glue
选项;结果还是一样。
非常感谢您的帮助。
最佳答案
功能文件中的“Given”等单词在功能文件中为大写。它们需要像给定的 ie 句子大小写一样。
Feature: Simple Test Feature
Scenario: Run Scenario ONE
Given step one
When step two
Then step three
此外,您可能需要将“src”附加到运行器中的功能路径中。如果您使用的是 Maven,就像这样 features = "src/test/resources/features"
。运行程序中也不需要有 @Test 注释和方法
。
关于java - 简单的 cucumber 测试类通过,无需胶水文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49759334/