The "Go" nose-parameterized is a parameterized extension of the Python Unit test framework

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.