Original address:
Http://www.cnblogs.com/fnng/p/6580636.html
In contrast, the unit test framework below Python is less weak, especially the Python-unittest test framework, which does not support parameterization, does not support multithreaded execution cases, and does not support the generation of HTML test reports .... Well again, part of the shortfall we can use unittest expansion to meet demand. For example, let's introduce a parameterized extension.
In the absence of parametric functionality, our use cases need to be written like this.
Import UnitTest class Testadd (unittest. TestCase): def test_add_01 (self): self.assertequal (1 + 2, 3) def test_add_02 (self): self.assertequal (2 + 2, 5) def test_add_ (self): self.assertequal (3 + 3, 6)if__name__'__main __': unittest.main ()
Nose-parameterized is a parameterized extension for the Python unit test framework. Support for different unit testing frameworks is also available.
GitHub Address: https://github.com/wolever/nose-parameterized
Then, UnitTest can write the use case like testng.
ImportUnitTest fromNose_parameterizedImportparameterizedclassTestadd (unittest. TestCase): @parameterized. Expand ([(" on", 1, 1, 2), (" Geneva", 2, 2, 5), ("Geneva", 3, 3, 6), ]) defTest_add (self, name, A, B, c): Self.assertequal (a+b, c)if __name__=='__main__': Unittest.main (verbosity=2)
Execution Result:
Test_add_0_01 (__main__. Testadd) ... ok
Test_add_1_02 (__main__. Testadd) ... FAIL
Test_add_2_03 (__main__. Testadd) ... ok
The more use cases for the same entry and assertion results, the better it is to use this notation!
The "Go" nose-parameterized is a parameterized extension of the Python Unit test framework