O'Reilly logo

Test Driven Development: By Example by Kent Beck

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

Chapter 5. Franc-ly Speaking

$5 + 10 CHF = $10 if rate is 2:1$5 * 2 = $10Make “amount” privateDollar side effects?Money rounding?equals()hashCode()Equal nullEqual object5 CHF * 2 = 10 CHF

How are we going to approach the first test, the most interesting test, on that list? It still seems to be a big leap. I'm not sure I can write a test that I can implement in one little step. A prerequisite seems to be having an object like Dollar, but to represent francs. If we can get the object Franc to work the way that the object Dollar works now, we'll be closer to being able to write and run the mixed addition test.

We can copy and edit the Dollar test:

public void testFrancMultiplication() {
					Franc five= new Franc(5);
					assertEquals(new Franc(10), ...

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