Structure Your Step Definitions

When we run our List fruit feature with mvn clean test, we’ll see the usual snippets:

 
@Given(​"^the system knows about the following fruit:$"​)
 
public​ ​void​ theSystemKnowsAboutTheFollowingFruit(DataTable arg1) ​throws​ ​Throwable​ {
 
// Write code here that turns the phrase above into concrete actions
 
// For automatic transformation, change DataTable to one of
 
// List<YourType>, List<List<E>>, List<Map<K,V>> or Map<K,V>.
 
// E,K,V must be a scalar (String, Integer, Date, enum etc)
 
throw​ ​new​ PendingException();
 
}
 
 
@When(​"^the client requests GET /fruits$"​)
 
public​ ​void​ theClientRequestsGETFruits() ​throws​ ​Throwable​ {
 
// Write code here that turns the phrase above into concrete ...

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.