I am often asked about how a history graduate ended up being a software developer. Usually I give some vague spiel about the parallels between the two (see my earlier post). A while back I got talking about TDD in the same breath, which led me to wonder: can I test drive an essay? It’s been too long since I’ve written an essay (and I can’t say I miss it), so I decided to test drive a book review instead.
Why do we need tests?
It’s the same reason I have brakes on my bike. The brakes allow me to go faster. More importantly, they allow me to go faster safely. I remember spending ages writing essays at university. Is TDD a technique I could have used to write my essays faster?
What exactly is Test Driven Development?
You write the test first and use the test to drive your development. Specifically you do as much development as needed to pass the test – and no more. In the case of writing a book review, the development is the writing itself. To write the test first you have to know what you want to achieve.
So what is the purpose of a book review?
A book review is something that tells you enough about the book that you can work out if you want to read it yourself or not.
My requirement then, is: As a user I want to know if I should read a particular book.
Therefore we have the following scenario:
Given a review is written about a book
When I read the review
I know if I want to read the book.
How do we know when the test passes?
The above assertion bothers me as it is very subjective and I don’t know how it can be proved. The closest parallel I can see to software development is the book review is like a UI as it is different for everyone. How do we test the look and feel of a UI? A common way is to survey people to see what they think. I can do something similar. I can get people to read the review, and answer the following question afterwards:
Do you want to read the book? (Yes / No / I don’t know)
The first two options mean the test passes, the last option means it fails.
Next: Essay Development…