[prog] Unit testing

John Stoneham lyric.programming at lyrically.net
Thu Sep 2 11:04:34 EST 2004


> So what do you think? Should unit tests be coded quickly or well?

Both, ideally. :)

Realistically your tests ought to be based on a framework such that each
individual test is easy enough to comprehend if you know the API (after all,
these are not use-case or system-level tests, they're unit tests for the
developers). Each test should be independent of every other so that if one
fails, the rest don't fail (if this is not the case you'll have more trouble
finding the original flaw). One test case (or test method) for each behavior
of each method you write plus any higher-level / combinatorial test cases you
feel are necessary.

Your test framework (what are you using? Something like JUnit or CppUnit?)
ought to give you the flexibility to do this; for me a test class for each
application class I write has seemed to serve me well, and I build a library
of test-helper classes with common setup/teardown/etc functionality in them.

Your tests generally shouldn't have to be very long if you have a proper
structure of helper classes built up to avoid duplicating large portions of
code.

Do you have specific examples you'd like to discuss?

- John


More information about the Programming mailing list