黄瓜未定义的步骤,虽然使用IntelliJ定义

OMG*_*POP 7 java intellij-idea cucumber

我正在尝试运行.feature文件来测试一个简单的RESTEasy Web应用程序:https://github.com/dashorst/jaxrs-quickstart-resteasy.

然而,IntelliJ一直说:

Undefined step: Given  I am an invalid username

Undefined step: When  I perform a hello request with null username

Undefined step: Then  I receive a http response code of 400

Undefined step: When  I perform a hello request with empty username

Undefined step: Then  I receive a http response code of 400

You can implement missing steps with the snippets below:

@Given("^I am an invalid username$")
public void I_am_an_invalid_username() throws Throwable {
    // Express the Regexp above with the code you wish you had
    throw new PendingException();
}
// similar results...
Run Code Online (Sandbox Code Playgroud)

以下是我的hello.feature档案:

Feature: hello

#-------------------------------------
#next block is got the GET entry point
#-------------------------------------

#verify that with malformed input hello fails 
Scenario: invalid username should fail
Given I am an invalid username
When I perform a hello request with null username
Then I receive a http response code of 400
When I perform a hello request with empty username
Then I receive a http response code of 400

#verify that you can get correct hello response with valid username. This is the 'everything works fine' path.
Scenario: User can get correct hello response with valid username
Given I am a valid username
When I perform a hello request with valid username
Then I receive a http response code of 200

import cucumber.annotation.en.Given;
import cucumber.annotation.en.Then;
import cucumber.annotation.en.When;
import cucumber.runtime.PendingException;
Run Code Online (Sandbox Code Playgroud)

我使用IntelliJ选项"生成步骤"并获取MyStepdefs文件.

/**
 * Created by z on 5/21/17.
 */
public class MyStepdefs {
    @Given("^I am a valid username$")
    public void iAmAValidUsername() throws Throwable {
        // Write code here that turns the phrase above into concrete actions
        throw new PendingException();
    }

    @Given("^I am an invalid username$")
    public void iAmAnInvalidUsername() throws Throwable {
        // Write code here that turns the phrase above into concrete actions
        throw new PendingException();
    }

    @When("^I perform a hello request with null username$")
    public void iPerformAHelloRequestWithNullUsername() throws Throwable {
        // Write code here that turns the phrase above into concrete actions
        throw new PendingException();
    }

    @Then("^I receive a http response code of (\\d+)$")
    public void iReceiveAHttpResponseCodeOf(int arg0) throws Throwable {
        // Write code here that turns the phrase above into concrete actions
        throw new PendingException();
    }

    @When("^I perform a hello request with empty username$")
    public void iPerformAHelloRequestWithEmptyUsername() throws Throwable {
        // Write code here that turns the phrase above into concrete actions
        throw new PendingException();
    }

    @When("^I perform a hello request with valid username$")
    public void iPerformAHelloRequestWithValidUsername() throws Throwable {
        // Write code here that turns the phrase above into concrete actions
        throw new PendingException();
    }
}
Run Code Online (Sandbox Code Playgroud)

我曾尝试为每个场景指定粘合路径,但它不起作用.我不知道发生了什么.谢谢你的建议!

我已经研究了几个现有的问题,但没有一个有用:

黄瓜:未定义的步骤,尽管应该定义步骤

黄瓜JVM未定义步骤

这是我的项目结构: 在此输入图像描述

Mr *_*Cas 8

有时,当保存了对软件包旧名称的引用时,就会发生这种情况。如果软件包已被重命名,则应检查是否存在对旧名称的引用(黄瓜运行/调试配置)并将其删除。

亲切的问候


小智 7

当上面有正确的解决方案时,我会逐步推荐一个解决方案。

  1. 通过 IntelliJ 中的“运行 > 编辑配置...”
  2. 从“Cucumber java”列表中选择你的Cucumber java类
  3. 用黄瓜实现所在的路径填充“胶水”。例如,“com.blabla.test.steps”
  4. 点击“应用”按钮
  5. 尝试运行/调试您的黄瓜特征文件


Giu*_*cin 6

尝试这个:

  1. 已安装Cucumber for Java插件,并且与您的intellij idea版本兼容
  2. 创建并将测试\资源标记为Test Resources Root
  3. .feature放入test \ resources
  4. test \ java中创建文件夹step_definitions并将您的测试代码放在此处
  5. 检查Feature配置包含step_definitionsGlue
  6. 检查step_definitions代码是否正确构建

经过这些检查后,步骤应被识别。