Я пытаюсь запустить Cucumber
тест с Spring Boot
и JUnit
.
Однако, я получаю следующую ошибку, когда щелкаю правой кнопкой мыши по классу TestRunner
.
Я что-то пропустил?
Ошибка:
cucumber.runtime.junit.UndefinedThrowable: The step "I feed my snake" is undefined
Feature: Snake Charmer
Scenario: Hearing your snake you anticipate sound # src/test/resources/features/first.feature:3
Given I have hungry snake # SnakeMeasureTest.i_have_hungry_snake()
When I feed my snake # null
Then I receive snek snek # SnakeMeasureTest.receive_snek_snek()
Undefined scenarios:
src/test/resources/features/first.feature:3 # Hearing your snake you anticipate sound
1 Scenarios (1 undefined)
3 Steps (1 skipped, 1 undefined, 1 passed)
0m1.378s
You can implement missing steps with the snippets below:
@When("I feed my snake")
public void i_feed_my_snake() {
// Write code here that turns the phrase above into concrete actions
throw new cucumber.api.PendingException();
}
SnakeMeasureTest.java
public class SnakeMeasureTest extends CucumberStepDefinitions {
@Autowired
SnakeController snake;
@Given("^I have hungry snake")
public void i_have_hungry_snake() {
assertEquals("hiss", snake.poke());
}
@When("^When I feed my snake$")
public void when_i_feed_my_snake() {
snake.feed();
}
@Then("^I receive snek snek$")
public void receive_snek_snek() {
assertEquals("snek snek ^_^", snake.poke());
}
}
CucumberStepDefinitions.java
@RunWith(SpringRunner.class)
@SpringBootTest
public abstract class CucumberStepDefinitions {
}
TestRunner.java
@RunWith(Cucumber.class)
@CucumberOptions(plugin = {"pretty"}, features = {"src/test/resources/features"})
public class TestRunner {
}
first.feature (источник / тест / ресурсы / функции)
Feature: Snake Charmer
Scenario: Hearing your snake you anticipate sound
Given I have hungry snake
When I feed my snake
Then I receive snek snek
SnakeController.java
@Controller
public class SnakeController {
private boolean fed;
@Autowired
public SnakeController() {
super();
}
public void feed() {
fed = true;
}
public String poke() {
if (this.fed == true) {
return "snek snek ^_^";
} else {
return "hiss";
}
}
}