The importance of unit testing is not much to say, hateful is that there are too many unit testing frameworks and tools in Python, what unittest, TestTools, subunit, coverages, testrepository, Nose, MOX, mock, Fixtures, Discover, plus setuptools, distutils, and so on, don't say how to write unit tests, just how to run unit tests there are n many ways, again because it is testing rather than function, is a l
Overview
1. Testing the Scaffold (test fixture)
The work to be done before the test is ready and the work to be done after the test is finished. Includes setup () and teardown ().
2. Testing cases (test case)
The smallest test unit.
3. Testing Suite (test suite)
A collection of test cases.
4. Test Runner (runner)
The component that tests the execution.
Command line interface
You can run test modules, test classes, and test methods with the command line.
The code is as follows:
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 caseTestSuite Multiple test cases are assembled
The examples in this paper describe the usage of unittest in Python and share them for your reference. The specific usage analysis is as follows:
1. The UnitTest module includes the ability to write run UnitTest, and the custom test class integrates unitest. TestCase class, test method begins with test, and the run or
UnitTest is the unit test framework for Python,Similar to the testng inside Java.From time import sleepFrom selenium import WebdriverImport UnitTestClass UnitTest (UnitTest. TestCase):# UnitTest class Inherits Unittest.testcase classdef setUp (self):# Setup is used to set up
Today, I wrote some unit tests using Python's UnitTest module, and now we have the following notes:The basic format for using UnitTest is as follows:ImportUnitTestclassTest (unittest. TestCase):defsetUp (self):Pass deftest_a (self):Pass defTest_b (self):Pass defTearDown (self):Passif __name__=='__main__': Unittest.main ()Basically the online has alre
Simple implementation of interface Automation testing (based on Python+unittest) introductionIn this paper, the basic interface test from the postman to get the simple interface test start, step-by-step optimization interface calls, and add basic results to judge, explain the Python's own unittest framework call, I hope you can through this article on the interfa
First, the operation processSecond, how to use:1, define an inheritance unittest. TestCase class in which the Test_ beginning method is the test case at the time of execution############################name:test_unittest.py#!/usr/bin/env python#_*_ coding:utf-8 _*_defAdd (A, b):returnA +bdefMinus (A, b):returnA-bdefmulti (A, B):returnA *bdefDivide (A, b):returnA/b###########################name:test_case.py
Overview
1. Testing Scaffold (Test fixture)
The work to be done before the test is prepared and the work to be done after the test is completed. Includes setup () and teardown ().
2. Testing cases (test case)
The smallest test unit.
3. Testing Suites (test suite)
A collection of test cases.
4. Test Runner
The component that the test executes.
Command-line interface
You can run test modules, test classes, and test methods using the command line.
Copy Code code as follows:
empty.When not empty, you can write a module import statement under a package in a file, because the __init__.py file is imported when the module is actually imported.3. Import Module Statement formatImport Module NameFrom Package name Import module name (only one module in the package is imported)From package name. module Name Import function name (when a specific function in the module needs to be imported)4..pycache fileThe module is executed when it is imported, and the
run, the test was not counted as a failure. Translation: When the assertion is skipped (temporarily do not know what to use, did not understand, seemingly assertion failure, also become a use case pass.) )
Twoskip案例Operation Result:Test 1Test 4. SSX----------------------------------------------------------------------Ran 4 tests in 0.003sOK (skipped=2, expected Failures=1)Third, skip the entire test classIv. Reference Code:# Coding:utf-8Import UnitTestClass Test (
The importance of unit testing is not much to say, hateful is that there are too many unit testing frameworks and tools in Python, what unittest, TestTools, subunit, coverages, testrepository, Nose, MOX, mock, Fixtures, Discover, plus setuptools, distutils, and so on, don't say how to write unit tests, just how to run unit tests there are n many ways, again because it is testing rather than function, is a l
Brief introduction of UnitTest frameworkThe UnitTest unit test framework can be applied not only to unit testing, but also to the development and execution of automated test cases for Web UI and interface APIs that organize the execution of test cases, and provide a rich assertion method to determine whether test cases pass and ultimately generate test results.I. Overview of the
Python + requests + unittest API test, requestsunittest
The Black Bear searched for information related to the interface test on the Internet. Most of them focused on maintaining the use case in a text or table in the form of data-driven. They did not explain how to generate the desired use case,
Problem:
When testing interfaces, for example, parameters a, B, and c, I need to test the parameter first. There
Uencefunctions ("Test_shuffle"),testsequencefunctions ("Test_choice"), Testsequencefunctions ("Test_sample") ]) Suite = UnitTest. Testloader (). Loadtestsfromtestcase (testsequencefunctions) #使用测试套件并打包测试用例 Suite = UnitTest. TestSuite (Suite) #保存unittest的测试输入日志到文件 log_name= "E:\\test4\\log.txt" #verbosity =2 refers to the level of detail of the outpu
, Automatically searches CAs in the specified directory, constructs the test set, executes the order of names: Executes the Test_add first, then executes test_sub discover = Unittest.defaultTestLoader.discover (test_ Dir, pattern= ' test_*.py ') # instantiates Texttestrunner class runner = UnitTest. Texttestrunner () # Run the test suite with the Run () method (that is, run all the use cases in the test suite) Runner.run (Discover)The a
Using assert assertions is a very good habit of learning python, and Python assert asserts that the sentence format and usage are simple. Before we can complete a program, we don't know where the program is going to go wrong, and instead of letting it crash at the top of the run, it's better to crash when the error con
Test steps1. Import the UnitTest module
Import UnitTest
2. Write the test class inheritance unittest. TestCaseClass Tester (UnitTest. TestCase)
3. Methods for writing tests must begin with testdef test_add (self)def test_sub (self)
4. Test the function points using the method provided by the TestCase class
5. Call th
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.