Unit tests
Introduction
Unit tests are a godsend, if you can do them right.
Software for Unit Tests
Tips
- Don't be dumb. Write smart unit tests. If writing the tests are boring, then you are doing something wrong, probably testing stuff you already know works.
- Write down a list of common tests. For instance, if a number is accepted, then you are always going to pass in these values: 1, 0, -1, 65535, 65536, -65536, etc... For strings: null/None/0, "", "\x00asdf", etc... In other words, if there is a limit, you will test that limit.
- You have little tests and big tests. If your little tests are hard to write, then you haven't written little code, meaning, your tiniest bits of code are WAY too complicated and you need to rethink how you are keeping things modularized. If your big tests are hard to write, that's because they are hard to write. Do yourself a favor by writing support methods that make your job easier.
- Don't forget that unit tests are code and can be driven by data as much as any program can. Write a "do_test(setup, parameters, expected)" method, and then a kazillion tests that call "test_this(special paramaters, expected result)". Or better yet, iterate through a set of parameter-expectation combinations.