unittests makes it easy to create more complex tests. If you have a test that involves calling several helper functions, iterations, and other analyzes, doctrines may feel limited. unittests , on the other hand, just writes Python code - anything you can do in Python you can do there conveniently. Take this code (a modified version of unittest that I once wrote):
def basic_tests(self, cacheclass, outer=10, inner=100, hit_rate=None): c = cacheclass(lambda x: x + 1) for n in xrange(outer): for i in xrange(inner): self.assertEqual(c(i), i + 1) if hit_rate != None: self.assertEqual(c.hit_rate(), hit_rate) def test_single_cache(self): self.basic_tests(SingleCache, outer=10, inner=100, hit_rate=0) sc = SingleCache(lambda x: x + 1) for input in [0, 1, 2, 2, 2, 2, 1, 1, 0, 0]: self.assertEqual(sc(input), input + 1) self.assertEqual(sc.hit_rate(), .5)
I use the basic_tests method to run some tests in the class, and then run the statement in a for loop. There are ways to do this in doctrines, but they require a lot of thought. Teaching is best tested to ensure that specific individual function calls return the values ββthey need. (This is especially true in Django, which has fantastic unit testing tools (see django.test.client ).