Test Driven Development A brief introduction – A brief introduction



Test Driven Development A brief introduction – A brief introduction

0 0


ttd_talk


On Github ollyjshaw / ttd_talk

Test Driven Development

A brief introduction

Created by Olly Shaw (Team 6)

Welcome

About me: Lead dev on team 6

Target audience: Developers

Who is "doing TDD"?

Unit Testing all the classes in the codebase?

Using tools like JUnit?

Using Mocks?

Using BDD?

Nope!

What doing TDD is

Write a failing test

Write the code to make that test pass

Refactor to make the code cleaner

RED

GREEN

REFACTOR

Demo, Bowling Kata

The game consists of 10 frames as shown above. In each frame the player has two opportunities to knock down 10 pins. The score for the frame is the total number of pins knocked down, plus bonuses for strikes and spares.

A spare is when the player knocks down all 10 pins in two tries. The bonus for that frame is the number of pins knocked down by the next roll. So in frame 3 above, the score is 10 (the total number knocked down) plus a bonus of 5 (the number of pins knocked down on the next roll.)

Bowling Kata

A strike is when the player knocks down all 10 pins on his first try. The bonus for that frame is the value of the next two balls rolled.

In the tenth frame a player who rolls a spare or strike is allowed to roll the extra balls to complete the frame. However no more than three balls can be rolled in tenth frame.

Let's Code!

TDD Levels

public class Frame{

  public boolean isComplete(){
    //Some code here
  }
  
  public int calculateFrameScore(Frame next, Frame nextPlusOne){
    //Some code here
  }
 
  public totalKnockedDownThisFrame(){
    //Some code here
  }

}
            

What is a Unit?

Test units of behaviour

Don't test units of Code

It's what Kent Beck was doing!

TDD Gears

Mocks

Don't mock what you don't own!

A Dummy class is a mock

Don't mock what you don't own!

"Wrapping your third party libraries in objects, and then using those objects in your code (rather than the library directly) is just good practice."

Eric Smith 8th Light

A Dummy class is a mock

public class MockFrame implements Frame{
  public boolean isComplete(){
   return true; //I'm always complete!
  }
}