Implementing Our First Step Definition

We’ve decided this first release of our checkout is going to be a class that takes the price list and the items being bought as arguments to a method. So, our job in the step definition for Given the price of a banana is 40c is just to remember the price of bananas. In the step_definitions folder, edit the CheckoutSteps.java file so that the first step definition looks like this:

first_taste/05/step_definitions/CheckoutSteps.java
 
@Given(​"^the price of a \"(.*?)\" is (\\d+)c$"​)
 
public​ ​void​ thePriceOfAIsC(​String​ name, ​int​ price) ​throws​ ​Throwable​ {
 
int​ bananaPrice = price;
 
}

Great, that was easy. Now, where were we again? Well, we’ve written some Java code so we’ll need to compile 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.