gpt4 book ai didi

java - Cucumber 未定义的步骤,虽然使用 IntelliJ 定义

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:50:14 27 4
gpt4 key购买 nike

我正在尝试运行一个 .feature 文件来测试一个简单的 RESTEasy 网络应用程序: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...

下面是我的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;

我使用了 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();
}
}

我曾尝试为每个场景指定粘合路径,但它不起作用。我不确定发生了什么。感谢您的任何建议!

我研究了几个现有的问题,但没有一个有帮助:

Cucumber: undefined step, although step should be defined

Cucumber JVM undefined step

这是我的项目结构: enter image description here

最佳答案

Sometimes it happens when there are saved references to the old names of the packages. If the packages have been renamed you should check if there are references to the old names (Cucumber Run/Debug Configurations) and delete them.

亲切的问候

关于java - Cucumber 未定义的步骤,虽然使用 IntelliJ 定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44102161/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com