A collection of exercises for practicing TDD and refactoring
The code used in this exercise is based on the Composed Method refactoring example from Joshua Kerievsky's book, "Refactoring to Patterns"
You are trying to coach a developer who has a working knowledge of JUnit but very little experience with TDD and refactoring. The developer is willing to learn about TDD but is also skeptical about its effectiveness. He thinks that all the examples he has seen are too simple or contrived and that the demonstrations he has seen lacked authenticity and came across as canned and scripted to make TDD appear easy and effective.
None of the previous attempts he has made to do TDD with real-world code went well, making him even more skeptical that the technique actual works. He's willing to accept that he's missed something but wants you to show him what exactly he's not getting about TDD.
He issues a challenge to you: Demonstrate TDD on code that you've never seen before and gives you some simple but non-trivial code that is supposed to be a good exercise for learning TDD and refactoring. If you can show him how to use TDD to work through this code, refactor it, and make some design improvements/enhancements to it, he's willing to give TDD some serious consideration.
Some things you might want to discuss/demonstrate:
- Reasons for changing code
- Code smells
- Reasons for refactoring
- The role of unit tests in refactoring and TDD
The code used in this exercise is taken directly from Jason Gorman's experiment on TDD as described here: http://www.codemanship.co.uk/parlezuml/blog/?postid=1019
See Jason's blog post for details on how to go through this exercise.
The code used in this exercise is from Jay Fields first example in his book "Working Effectively with Unit Tests" (WEWUT)
You have some code with a couple of broken tests. You need to find the bug and fix it, doing some refactoring and TDD along the way.