Behavior Driven Development with JUnit 5. Part 5

  • The Cucumber plugin generates a method annotated with @Given(“^there is an economy flight$”), meaning this method is executed when the step Given there is an economy flight from the scenario is executed #1.
  • The plugin generates a method stub to be implemented with the code addressing the step Given there is an economy flight from the scenario #2.
  • The plugin generates a method annotated with @When(“^we have a regular passenger$”), meaning this method is executed when the step When we have a regular passenger from the scenario is executed #3.
  • The plugin generates a method stub to be implemented with the code addressing the step When we have a regular passenger from the scenario #4.
  • The plugin generates a method annotated with @Then(“^you can add and remove him from an economy flight$”), meaning this method is executed when the step. Then you can add and remove him from an economy flight from the scenario is executed #5.
  • The plugin generates a method stub to be implemented with the code addressing the step Then you can add and remove him from an economy flight from the scenario #6.
  • The rest of the methods are implemented in a similar way; we have covered the Given, When, and Then steps of one scenario.
  • We declare the instance variables for the test, including economyFlight and mike as a Passenger #1.
  • We write the method corresponding to the Given there is an economy flight business logic step #2 by initializing economyFlight #3.
  • We write the method corresponding to the When we have a regular passenger business logic step #4 by initializing the regular passenger mike #5.
  • We write the method corresponding to the Then you can add and remove him from an economy flight business logic step #6 by checking all the conditions using the assertAll JUnit 5 method, which can now be read fluently #7.
  • The rest of the methods are implemented in a similar way; we have covered the Given, When, and Then steps of one scenario.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store