SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: UnitTesting old code
-
Mar 31, 2005, 03:37 #1
UnitTesting old code
I've been working on my own class library over the past couple of weeks, but its only in the past few days that I've been getting my head around Unit Testing. I'm happy to start giving it a go, but I have one question: is it worth going back and writing tests for all of the classes I've already written.
If yes, how would you go about doing this (bearing in mind that the idea is you would usually write the tests first).
Cheers.
-
Mar 31, 2005, 06:56 #2
- Join Date
- Sep 2003
- Location
- Glasgow
- Posts
- 1,690
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Yes - definitely.
Testing will lead you to think more carefully about the classes: I bet you find a few bugs you didn't know about.
Testing can also suggest improvements: changing classes to make them easier to test usually leads to a better design (one of the many wonderful things about testing).
As you develop your library it will always remain in a functional state if you run all tests after each edit and always fix any failing tests (regression testing). For that to work everything will need to be covered by tests, of course.
how would you go about doing this
Once you've got the hang of testing you won't ever want to work any other way again.
-
Mar 31, 2005, 06:58 #3
- Join Date
- Jun 2003
- Location
- Iowa, USA
- Posts
- 3,749
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You might just do it as you make additions or need to refactor the existing libraries.
If you can justify it to yourself as a learning excesize, then I would say wrap some of your existing working code in tests, but if you find it to be feeling like drudge work, and discouraging you from writing test, move on to using tests in your new development work where you can realize much more tangable immediate benefits.Jason Sweat ZCE - jsweat_php@yahoo.com
Book: PHP Patterns
Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
Detestable (adjective): software that isn't testable.
Bookmarks