Cucumber-JVM 步骤定义

Cucumber-JVM Step definitions

在 eclipse 中创建我的功能文件后,我 运行 它作为 Cucumber 功能。我使用控制台给我的步骤定义来创建测试文件的第一个基础

@Given("^the input is <(\d+)> <(\d+)>$")

这些应该由控制台输出,但目前它显示的是没有步骤定义的功能。

Feature: this is a test
  this test is to test if this test works right

  Scenario: test runs # src/test/resources/Test.feature:4
    Given: i have a test
    When: i run the test
    Then: i have a working test


0 Scenarios
0 Steps
0m0,000s

此功能只是为了检查黄瓜是否正常工作。

运行 人:

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(
        monochrome = true,
        dryRun = false,
        format = "pretty",
        features = "src/test/resources/"
        )
public class RunCukes {
}

控制台没有显示所有信息的原因是什么?

TL:DR 控制台不显示缺少步骤的步骤正则表达式

编辑:添加了功能文件

Feature: this is a test
  this test is to test if this test works right

  Scenario: test runs
    Given: i have a test
    When: i run the test
    Then: i have a working test

问题出在功能文件中。在 GivenWhenThen 之后使用 : 是问题。我能够使用您的功能文件重现您的问题。但是当我使用上面提供的相同 Runner 选项删除 : 和 运行 功能文件时,我得到了正则表达式来实现缺少的步骤定义。

P.S 我正在使用 IntelliJ,但我认为这不会有什么不同。

  Feature: this is a test
  this test is to test if this test works right

  Scenario: test runs # src/test/resources/Test.feature:4
    Given i have a test
    When i run the test
    Then i have a working test

下面是我得到的:

Testing started at 19:12 ...

Undefined step: Given  i have a test

1 Scenarios (1 undefined)
3 Steps (3 undefined)
0m0.000s

Undefined step: When  i run the test

You can implement missing steps with the snippets below:
@Given("^i have a test$")

public void i_have_a_test() throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@When("^i run the test$")
public void i_run_the_test() throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Then("^i have a working test$")
public void i_have_a_working_test() throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}


Undefined step: Then  i have a working test

1 scenario (0 passed)
3 steps (0 passed)
Process finished with exit code 0

如果您的 .feature 文件因某种原因无效,则可能会发生这种情况。我曾经有过它发生只是因为我有两个 ||在我的场景大纲

的示例 table 中