Writing tests is pain because your code is not written to be testable. Why not try something called Test-Driven Developement?
Example: You need software which involves dogs…
So you probably need a class called Dog. Instead of writing the class first, try to imagine what you would like the class to do. Don’t just imagine it; write a test which demonstrates how you want your dog to act.
class DogTest(unittest.TestCase): def testBark(self): dog = Dog() self.assertEqual('wuh', dog.bark())
You run the test and see it fail. Obviously, since there is no Dog yet! What you have done is that you’ve made a design decision, that you wan’t the dog object to bark by calling its bark method. Now you only need to implement it, and it’s a breeze since you already have the test to back it up:
class Dog(): def bark(self): return 'wuh'
Congrats.. You’re test driving! Simple, isn’t it?
For more information try google or some of these links:
http://www.agiledata.org/essays/tdd.html
http://blog.objectmentor.com/articles/2007/07/17/testing-will-challenge-your-conventions
http://tech.groups.yahoo.com/group/testdrivendevelopment/
http://www.testdriven.com
In retrospective I really need to emphasize that this is not what Test-Driven Development is all about. This was just a two-minute example for a friend with no knowledge about “test-first”, no knowledge about what it means to write a test before code. A poor attempt to demonstrate the act of design by writing tests. If you really want to know about TDD, check out the links. You really should, it might save your life (or sanity at least), especially if you’re in sw development.