Test-Driven Development

Alexis Pavlidis

Apprentice Software Craftsman @Codurance

eXtreme Programming

What is TDD?

Unit testing - but not TDD

Step 1: write logic

Step 2: write tet(s)

Test-Driven Development

Step 1: write test

Step 2: write logic

The 3 Laws of TDD

  1. You can’t write any production code until you have first written a failing test.
     
  2. You can’t write more of a unit test than is sufficient to fail, and not compiling is failing.
     
  3.  You can’t write more production code than is sufficient to pass the currently failing unit test.

 

Why TDD?

Eliminate Fear

Benefits of TDD

  • Design

  • Reduce Debugging time

  • Documentation

  • Courage

Arrange, Act, Assert

FIRST Principles

  • Fast
  • Independent
  • Repeatable
  • Self-validating
  • Timely

The rules

You are trapped in a cycle of ~2min

  1. Write a failing unit test that tests only one thing
     
  2. Write the simplest code to make that test pass
     
  3. Refactor if necessary
     
  4. Repeat

Demo

Advanced TDD

  • Mocking

  • Outside-In

  • Legacy Code

  • London vs Chicago schools of TDD

  • Transformation Priority Premise

Further Reading

Thank you 🎉

Test Driven Development

By Alexis Pavlidis

Test Driven Development

  • 862