没有参数的步骤定义是不可能的吗?

Is it not possible to have a step definition with no parameters?

我有以下场景:

Feature: Spheres
  Scenario: A ray intersects a sphere at two points
    Given r ← ray(point(0, 0, -5), vector(0, 0, 1))
    And s ← sphere()
    When xs ← intersect(s, r)
    Then xs.count = 2
    And xs[0] = 4.0
    And xs[1] = 6.0

为了保持简单,我想我应该从字面上写下步骤定义来开始:

import io.cucumber.java8.En

class SphereStepDefinitions: En {
    private val epsilon: Double = 0.00001
    lateinit var s: Sphere
    lateinit var xs : List<Double>

    init {
        Given("s ← sphere\()") {
            s = Sphere()
        }
    }
}

结果,

The step "s ← sphere()" is undefined. You can implement it using the snippet(s) below:

Given("s ← sphere\()", () -> {
    // Write code here that turns the phrase above into concrete actions
    throw new io.cucumber.java8.PendingException();
});

这与我已经指定的步骤字符串完全相同。 :(

我已经在项目中执行了很多工作步骤,但我认为这是我尝试过的第一个没有任何参数的步骤...这是行不通的吗?

我在 Java 11 上将 cucumber-jvm 5.7.0(也尝试过 5.6.0 和 6.0.0-RC2)与 Kotlin 1.3.72 一起使用。

您现在正在使用 Cucumber 表达式。看起来像 Cucumber doesn't generate the proper cucumber expression snippet.

您可以使用正则表达式(通过使用 ^$):

^s ← sphere\(\)$

或使用:

s ← sphere() 来解决这个错误。我会推荐前者而不是后者。