PYTHON-ZX note 9-unit test

Source: Internet
Author: User

unittest Core to be Vegetarian

1.TestCase

a An instance of TestCase is a test case. What is a test case? is a complete test process, including pre-test preparation Environment setup, execution of test code (run), and post-test environment restore (tearDown) . the nature of the meta-Test (unit test) is here, a test case is a complete test unit, which can be verified by running the test unit.

2.TestSuite

The combination of multiple test cases isTestSuite, andTestSuiteYou can also nest nestedTestSuite. Testloaderis used to loadTestCaseto theTestSuite, of which there are severalloadtestsfrom__ ()method is to find from every placeTestCase, create an instance of them, and thenAddto theTestSuite, and then returns aTestSuiteinstance.

3.TextTestRunner

Texttestrunner is to execute the test case where run (test) executes the testsuite/testcase in the Run (Result) method. The results of the test are saved to the texttestresult instance, including information about how many test cases were run, how many succeeded, and how many failed.

4.Fixture

The construction and destruction of a test case environment is a fixture.

calculator.pyclass  Math:    def__init__(self,a,b):        = Int (a)        = int (b)    def  Add (self):        return SELF.A + self.b    def  Jian (self):        return self.a-self.b

Unit Test

1  fromCalculatorImportMath2 ImportUnitTest3 4 classTestmath (unittest. TestCase):5     defsetUp (self):6         Print("Start Test")7 8     defTest_add (self):9j = Math (5,10)TenSelf.assertequal (J.add (), 15) One         #self.assertequal (J.add (), A  -     defTearDown (self): -         Print("Test End") the  - if __name__=='__main__': -     #Constructing test Sets -Suite =UnitTest. TestSuite () +Suite.addtest (Testmath ("Test_add")) -  +     #Perform tests ARunner =UnitTest. Texttestrunner () atRunner.run (Suite)

PYTHON-ZX note 9-unit test

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.