python - How to reuse the same tests to test different implementations? -
my language python 3
, trying understand how use same set of tests test different implementations of same algorithm.
so far looking @ built-in unittest
, impression have make sort of class hierachy: class inherits unittest.testcase , implements actual tests , several descendants class each test particular implementations tests parent.
however, idea of how should like. please tell me how use same set of tests test different functions implement same algorithm?
i've done writing tests in class not inherit testcase
, writing multiple test classes do inherit testcase
and tests, either have factory method or class attribute of class instantiate:
class testanyimplementation: def testthis(self): obj = getimpl() # call factory method self.asserttrue(obj.isempty()) class testfooimplementation(testanyimplementation,testcase): def getimpl(self): return foo() class testbarimplementation(testanyimplementation,testcase): def getimpl(self): return bar()
Comments
Post a Comment