SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru silver trophy Luke Redpath's Avatar
    Join Date
    Mar 2003
    Location
    London
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.

  2. #2
    simple tester McGruff's Avatar
    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
    Just write the tests. Try to write the minimum you need to get an inductive proof. The tests are a constraint on the design: add everything you need to check but don't add anything more than you have to. Over-constraining the design could impede later refactorings.

    Once you've got the hang of testing you won't ever want to work any other way again.

  3. #3
    eschew sesquipedalians silver trophy sweatje's Avatar
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •