O'Reilly logo

The Cucumber for Java Book by Seb Rose, Matt Wynne, Aslak Hellesoy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Testing Our Checkout Class

To implement the next step, edit step_definitions/CheckoutSteps.java so that the second step definition looks like this:

first_taste/07/step_definitions/CheckoutSteps.java
 
@When(​"^I checkout (\\d+) \"(.*?)\"$"​)
 
public​ ​void​ iCheckout(​int​ itemCount, ​String​ itemName) ​throws​ ​Throwable​ {
 
Checkout checkout = ​new​ Checkout();
 
checkout.add(itemCount, bananaPrice);
 
}

This code attempts to call an add() on an instance of our Checkout class, passing it the number of items being bought and their price.

This time when we run ./cucumber, we should get a compile error because we haven’t created a Checkout class yet:

 
step_definitions/CheckoutSteps.java:15: error: cannot find symbol
 
Checkout checkout = ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required