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

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -