Java cucumber.runtime.junit.UndefinedThrowable:步骤未定义

Java cucumber.runtime.junit.UndefinedThrowable:步骤未定义,java,junit,cucumber,Java,Junit,Cucumber,对于两个不同的类,我有一个场景 我的黄瓜结构: 测试等级: @RunWith(Cucumber.class) @CucumberOptions(plugin = "pretty", features = "src\\test\\resources\\samuel\\tripleAnd.feature")//and.feature in first case public class CucumberTest { } 执行: public class ElementsTestSteps i

对于两个不同的类,我有一个场景

我的黄瓜结构:

  • 测试等级:

    @RunWith(Cucumber.class)
    @CucumberOptions(plugin = "pretty", features = "src\\test\\resources\\samuel\\tripleAnd.feature")//and.feature in first case
    public class CucumberTest {
    
    }
    
  • 执行:

    public class ElementsTestSteps implements En {
    
    public ElementsTestSteps() {
    
        Given("^Element test$", () -> {
    
        });
    
        When("^Using element as \"([^\"]*)\"$", (String arg1) -> {
        });
    
        //Commented on when using the second scenario
        When("^Accept (\\d+) (\\d+)$", (Integer arg1, Integer arg2) -> {
        });
    
        //Commented on when using the first scenario
        When("^Accept (\\d+) (\\d+)$ (\\d+)$", (Integer arg1, Integer arg2, Integer arg3) -> {
        });
    
        Then("^Return (\\d+)$", (Integer arg1) -> {
        });
    }
    
    }
    
  • 当我使用以下
    和.feature
    功能时,它们都能正常工作:

    Scenario Outline:
    Given Element test
    When Using element as "and"
    And Accept <switchA> <switchB>
    Then Return <resultSign>
    
    Examples:
      | switchA | switchB | resultSign |
      |       1 |       1 |          1 |
      |       0 |       1 |          0 |
      |       1 |       1 |          1 |
      ...
    

为什么在第一种情况下一切都顺利,而在第二种情况下一切都不顺利?您的第二个accept regexp是错误的。在该表达式中,$符号出现两次。$指下线结束。删除第一个$,它应该可以正常工作。看起来像是一个简单的复制粘贴错误。

下面的步骤定义函数中有一个简单的问题。在第二个(\\d+)之后,您得到了一个额外的$符号

When("^Accept (\\\d+) (\\\d+)$ (\\\d+)$", (Integer arg1, Integer arg2, Integer arg3) -> {
    });

带有3个参数的步骤定义的正则表达式有一个错误
$
When("^Accept (\\\d+) (\\\d+)$ (\\\d+)$", (Integer arg1, Integer arg2, Integer arg3) -> {
    });