简体   繁体   中英

Cucumber .feature file not picking up Step Definition in Java class

I am writing some cucumber tests for my java project. My tests are working just fine, but there is a small warning appearing in my .feature file.

Below, I am passing an integer from the .feature file into my Step Definitions in a seperate java class

A yellow squiggly line appears under the below step in my .feature file:

Then the status code should be <StatusCode>

The warning message I receive is:

No definition found for the status code should be

Here is my feature file examples table:

| StatusCode |
| 200        |

And below is my Step Definition:

@Then("^the status code should be (\\d+)$")

This error is preventing me from Ctrl + Clicking the ' Then ' statement to bring me to the above Step Definition in my java class.

Does anyone have any suggestions about what may be going wrong?

Maybe this isn't the way you should be passing an integer through an examples table

The regexp to match the step method must match the text in the step (literally).

If your step is

Then the status code should be <StatusCode>

the regexp in your glue code

@Then("^the status code should be (\\d+)$")

would not match (hence you cannot CTRL+click it) the StatusCode .

Following simple example would work.

Scenario Outline: outline
  Given something
  Then the status code should be <StatusCode>
  Examples:
    | StatusCode |
    | 200        |

and the linked step definition

@Then("^the status code should be ([^\"]*)$")
public void theStatusCodeShouldBe(String statusCode) throws Throwable {
    ...
}

edit If you want to pass the status code as Integer you might change the signature of the step definition as

@Then("^the status code should be ([^\"]*)$")
public void theStatusCodeShouldBe(Integer statusCode) throws Throwable {
    ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM