tdd

Test Driven Development

Why?


twitter knows all


ACRONYMS!


KISS

YAGNI

(Better) API

first steps


This is the hard part

The evolution, not the artefacts

conway's game of life



1. Any live cell with fewer than two live neighbours dies, as if caused by under-population.
2. Any live cell with two or three live neighbours lives on to the next generation.
3. Any live cell with more than three live neighbours dies, as if by overcrowding.
4. Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.

first test


Compiler is your friend!

var cell = new Cell(); 


Check that evolve() function exists


assert.notEqual("undefined", cell.evolve) 

C# FTW


First test might look something like:

[TestMethod]public void LiveCellWithZeroNeighboursWillDie()
{
    var cell = Cell { CurrentStatus = CellStatus.Alive, NeighbourCount = 0 };

    cell.Evolve();

    Assert.AreEqual(CellStatus.Dead, cell.CurrentStatus);
}

Next


Make it compile!

(protip: R# is your friend)

RUN THE TEST


We expect it to go RED

This is *really* important

implement the feature


Make the test go GREEN

This is also *really* important

refactor


Improve the implementation

Safety net (green test) in place

rinse and repeat


Next feature:

RED
GREEN
REFACTOR

show me teh codez!

tdd

By ianr

tdd

  • 1,145