Test Driven Development is software development process that relies on the repetion of a very short development cycle: first you write a test, watch your tests fail, then refactor your code until the tests pass. This test-first process is repeated until the application is complete.
For this demonstration I'll be using qUnit as it has a nice browser based test runner. The same concepts should apply to other frameworks as well.
- jQuery in Action: Second Edition by Bear Bibeault and Yehuda Katz
To get started we've downloaded qUnit and created a simple scaffolding.
Clone this repository and reset it to the commit your interested in (in this case the first one, ac3e163395):
$ git clone email@example.com:MarkBennett/IntroToJsTdd.git $ git reset --hard <commit>
We've now got five files in our directory:
This scaffolding comes straight from the qUnit repo.
To begin try running your tests by opening test/index.html in your browser. If everything worked you should see a clean test runner. When you've got it working move on to the next commit to see how we add a new test.