Seeing It in Action

OK. So these are the three test cases we are going to TDD out.

images/tdd/3testsfilled.png

We will just take these logically in the order a user would as if they were using the calculator. Let’s start with entering a single number.

Step 1: Write a Failing Test

images/tdd/single.png

Show time. Time to put your design beret on and see if you can’t write a test that does two things:

  1. Verifies our calculator can take a single number
  2. Then returns the result (which for us will always be the last number added or operated on)

Take a moment and try writing a unit test that could do that. ...

Get The Way of the Web Tester now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.