Python UnitTest Learning notes (i)

Source: Internet
Author: User

One: Understanding UnitTest

Unittest:python internal Unit test module; junit similar to Java;

II: UnitTest Basic use

1:import UnitTest

2: Define a test class that inherits UnitTest. TestCase

3:setup and teardown, each test function is run before and after execution

4: Define test function, name starts with test

5: The main call assertequal, assertraises and other assertion methods to determine whether the program execution results and expected values are consistent

6: Call Unittest.main () to start the test

(1) Below we look at the specific code, as well as the results of the operation:

(2) In fact, we can also add parameters to Unittest.main (): Print the details as shown in:

The verbosity here is an option that identifies the information complexity of the test results, with three values:

0 (silent mode): can only get the total number of test cases and total results such as a total of 100 failed 20, the success of 80

1 (default mode): Very similar to silent mode, except for each successful use case preceded by a ".", each failed use case preceded by an "F"

2 (verbose mode): test results show all relevant information for each test case

(3) When the use case execution error, will give the error prompt, such as: we can according to the error prompt to locate the error location;

Above, we are the simplest example of unittest, but it is also a very important beginning.

Python UnitTest Learning notes (i)

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.