Test-Driven

Development


London Software Craftsmanship

Who?

 
Gonçalo Silva Samir Talwar
 

What.


It's quite, simple, really.


  1. Write a failing test.

  2. Write the simplest code possible to make the test pass.

  3. Refactor mercilessly.

Why?


There are many reasons why we write tests first, but they all boil down to confidence.

How?


  1. Start your editors.

  2. Create a failing test.
    assertEquals(1, 2); 
  3. Run it, and make sure it's red.

  4. Make it pass.
    assertEquals(1, 1); 
  5. Run it, and make sure it's green.

The Checkout Kata

https://github.com/7digital/kata-checkout


 We’re going to see how far we can get in implementing a supermarket checkout that calculates the total price of a number of items. In a normal supermarket, things are identified using Stock Keeping Units, or SKUs. In our store, we’ll use individual letters of the alphabet (A, B, C, and so on).

Our goods are priced individually. In addition, some items are multipriced: buy n of them, and they’ll cost you y pounds. For example, item A might cost £50 individually, but this week we have a special offer: buy three As and they’ll cost you £130.

The Price and Offer Table


Item          
Price         
Offer
A £50 3 for £130
B £30 2 for £45
C £20  
D £15  


Our checkout accepts items in any order, so that if we scan a B, an A, and another B, we’ll recognize the two B’s and price them at 45 (for a total price so far of 95).


Let's Go.

Test-Driven Development

By Samir Talwar

Test-Driven Development

  • 493