Adding an Assertion

To get the last step working, change the last step definition in step_definitions/CheckoutSteps.java to look like this:

first_taste/10/step_definitions/CheckoutSteps.java
 
@Then(​"^the total price should be (\\d+)c$"​)
 
public​ ​void​ theTotalPriceShouldBeC(​int​ total) ​throws​ ​Throwable​ {
 
assertEquals(total, checkout.total());
 
}

We’re using a JUnit assertion to check that the expected total specified in the feature matches the total from our checkout. If it doesn’t, JUnit will raise an error. Before this can compile, we’ll need to add an import statement to step_definitions/CheckoutSteps.java:

first_taste/10/step_definitions/CheckoutSteps.java
 
import​ static org.junit.Assert.*;

We’ll also need to download the ...

Get The Cucumber for Java Book now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.