Python Unit Test UnitTest

Source: Internet
Author: User

Python has a self-contained unit test framework that is the UnitTest module, which is used for unit testing, which encapsulates some of the result methods returned by the checksum and some initialization operations before the use cases are executed.

Before you say UnitTest, say a few concepts:

TestCase is also a test case

TestSuite Multiple test cases are assembled together, that is TestSuite

Testloader is used to load testcase into Testsuite.

Texttestrunner is to execute a test case, the results of the test are saved to the Texttestresult instance, including how many test cases were run, how much success, how many failed, etc.

A simple unit test case is written below:

Here are some common assertions, that is, verifying the results

How to generate a test report, you need to add another module, Htmltestrunner, this module needs to install itself, using the execution of test cases will generate an HTML test report, there will be the results of each test case execution, the code is as follows:

If we have a lot of modules, each module is written under a lot of Python files, each python file has a test case, how to put the use case in this directory is executed, we must first find all the Python files in this directory, and then find the inside of the test cases, executed, The code is as follows:

Python Unit Test UnitTest

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.