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

Making It Pass

So, now that we have our solid failing Cucumber scenario in place, it’s time to let that scenario drive out a solution.

There is a very simple solution that will make the test pass, but it’s not going to get us very far. Let’s try it anyway, for fun:

first_taste/12/implementation/Checkout.java
 
package​ implementation;
 
 
public​ ​class​ Checkout {
 
public​ ​void​ add(​int​ count, ​int​ price) {
 
}
 
 
public​ ​int​ total() {
 
return​ 40;
 
}
 
}

Try it. You should see the scenario pass at last:

 
...
 
 
1 Scenarios (1 passed)
 
3 Steps (3 passed)
 
0m0.116s

Hooray! So, what’s wrong with this solution? After all, we already said that we want to do the minimum work that the tests will let us get away with, right?

Actually, ...

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