Skip to Content
Test Driven Development: By Example
book

Test Driven Development: By Example

by Kent Beck
November 2002
Intermediate to advanced
240 pages
5h 9m
English
Addison-Wesley Professional
Content preview from Test Driven Development: By Example

Chapter 16

Abstraction, Finally

We need to implement Sum.plus() to finish Expression.plus, and then we need Expression.times(), and then we’re finished with the whole example. Here’s the test for Sum.plus():

public void testSumPlusMoney() {
   Expression fiveBucks= Money.dollar(5);
   Expression tenFrancs= Money.franc(10);
   Bank bank= new Bank();
   bank.addRate("CHF", "USD", 2);
   Expression sum= new Sum(fiveBucks, tenFrancs).plus(fiveBucks);
   Money result= bank.reduce(sum, "USD");
   assertEquals(Money.dollar(15), result);
}

We could have created a Sum by adding ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Refactoring: Improving the Design of Existing Code

Refactoring: Improving the Design of Existing Code

Martin Fowler
Refactoring: Improving the Design of Existing Code

Refactoring: Improving the Design of Existing Code

Martin Fowler, Kent Beck, John Brant, William Opdyke, Don Roberts

Publisher Resources

ISBN: 0321146530Purchase book