当前位置: 首页 > 知识库问答 >
问题:

Cucumber-JVM步骤定义

丁文轩
2023-03-14
@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

共有1个答案

葛炜
2023-03-14

问题出在特征文件中。使用:给出后,什么时候和什么时候才是问题。我能用你的特写文件复制你的问题。但是当我移除:并使用上面提供的相同的Runner选项运行特性文件时,我获得了regex来实现缺少的步骤定义。

我正在使用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
 类似资料:
  • 我对Cucumber JVM无法获取步骤定义有问题。我在Runner文件中确实有@CucumberOptions。我的功能文件也有@SmokeTest标签。这个问题仍然存在。请帮助!我已经尝试解决这个问题几天了。 Maven 和 Java 版本: Apache Maven 3.0.4Java版本:1.6.0_65,供应商:Apple Inc. 项目结构: 演示-- 运行器文件: 包com.smok

  • 问题内容: 如何在其他项目中重用Cucumber-JVM步骤定义来测试一些典型的Web操作。关键是我仅使用典型场景操作的“步骤定义”实现创建了一些Java项目,例如: 我想在其他项目(包括在classpath中)中重用这些定义,只是为了编写自己的简单方案。但是当我运行该场景时(作为JUnit测试),Cucumber无法找到“步骤定义”。当我尝试扩展“步骤定义”类时,它给我一个错误,我无法扩展“步骤

  • 我今天将我的serenity和cucumber测试升级到2.6.0 en cucumber 6版本。只需要更改大量程序包,并且功能文件的步骤不再链接到步骤定义。如果我的cucumberrunner的设置 但是,如果我在功能文件中查看intellij,您将无法再单击步骤以转到定义。当我运行功能文件时,我会得到以下异常: 我不确定是什么地方出了问题,因为相同的代码适用于以前的版本

  • 自从我升级到最新的社区版IntelliJ 15.0.3以来,每当我使用alt-enter从功能定义文件自动生成步骤定义时,它都会以驼峰大小写而不是带下划线的常规样式创建方法。 例如,它过去是这样生成的 但现在它产生了通常的camelCase惯例: 有没有办法把这个设置改回第一种样式? 谢谢

  • 我不能为一个项目用cucumber执行简单的测试。我在Intellij13社区,使用cucumber插件。 我在features目录中编写了我的features文件,我还通过插件实现了创建它们的步骤。intellij可以识别功能文件中的我的步骤,它可以导航并转到步骤实现。当我尝试运行我的场景时,if无法声明“未定义的步骤”。任何帮助都将不胜感激。 以下是我如何组织我的项目:

  • 我要驱动执行的代码是: 因此,在一个实例中(当传入string=“have”时),我希望向我的方法中传入一个值,如objpolicyamendrequest.setcolor(“blue”); 另一个方法(当传递给string=“have not”时)我不想传递任何东西给这个方法。 我想我需要遵循if语句,但不确定Cucumber是否有帮助。 希望我说得有道理。我对编程还是有点陌生!