installment, I tried using the Python standard library module doctest and unittest to improve the testing in my utility set and lead you to experience with me (and point out some of the best ways).
The script gnosis/xml/objectify/test/test_basic.py gives a typical example of the shortcomings of the current test and the solution. The following is the latest version of the script:
Listing 1. test_basic.py
installment, I try to use the Python standard library module doctest and unittest to improve the testing in my utility toolset and lead you to experience with me (and point out some of the best methods).
Script gnosis/xml/objectify/test/test_basic.py gives a typical example of the shortcomings of the current test and the solution. The following is the latest version of the script:
Listing 1. test_basic.py
ImportUnitTestclassutest (unittest. TestCase):defTest_upper (self): self.assertequal ('Foo'. Upper (),'FOO')defTest_isupper (self): Self.asserttrue ('FOO'. Isupper ()) Self.assertfalse ('Foo'. Isupper ())if __name__=='__main__': Unittest.main ()Note: 0. Unnitest is a python-brought library that requires no additional installation for 1. Test Cases (testcase) are all made up of
Test-driven Development (TDD) development model is not a novelty today, its development thinking is in the development of a product function, the firstWrite the test code of the function, in writing development such as, for example, to write a function of dividing two numbers, then its test code should be:#!/usr/bin/env python#coding:utf-8import unittestclass testdiv (unittest. TestCase): def setUp (sel
There is a Python automation script for the identification and manipulation of common elements, which goes on to talk about Python class inheritance, its third unittest framework, and the application of the report collection package Htmltestrunner.Let's go straight to the code.Applications of UnitTest and Htmltestrunne
Pyunit section in Jpython and Jython.Use Pyunit to build your own test installationThe classes required to write tests can be found in the "UnitTest" module. This module is part of the standard library for Python 2.1 and later. If you are using an earlier version of Python, you should get this module from a separate pyunit release.To make this module work in you
Python unit test unittest instance details, pythonunittest
This example describes how to use unittest in python unit test. Share it with you for your reference. The specific analysis is as follows:
Unit testing, as a developer of any language, should be necessary, because when you come back to debug your complex progra
1 Test Case TestCaseThe most basic component of a software test is the test case , which Pyunit uses the TestCase class to represent the test case and requires that all classes used to perform the test must inherit from the class. The test code implemented by the TestCase subclass should be self-contained, which means that the test case can run either individually or with other test case constituent collections.TestCase is considered a running entity of the test unit in the Pyunit test framework
Use the unittest and doctest modules in Python, unittestdoctest
I want to be honest. Although I am the creator of a Python library in a widely used public domain, the unit tests introduced in my modules are very unsystematic. In fact, most of those tests are included in gnosis Utilities of Gnosis. xml. pickle and are written by contributors to this sub-package. I
Learn the Appium Python project the small partner will have a question, saying that now all the case is a way to add a method through a suite, but in the actual process we do not want this, we do the function is this:Suite = UnitTest. TestSuite () suite.addtest (Casetest ("test_02", parame=i)) unittest. Texttestrunner (). Run (Suite)This is what we do now, but wh
.----------------------------------------------------------------------Ran 1 Test in 0.000sOKIn fact, if we have 100 test cases for this class to write, do we have to write 100 times widget = Widget (' The widget ')? What is the purpose of our ape-like service? Never write duplicate codeSo UnitTest gives us a setup,setup is a function that is executed before each test case runtest, which is equivalent to providing us with a way to prepare the environm
UnitTest is a unit test framework that is a unit test framework for Python programming. Sometimes it is called "Pyunit", which is the Python language version of JUnit. Here, JUnit is the Java Language Unit test framework, Java has a very useful unit test framework called TESTNG, this series only learn python, so only n
This article describes how to use unittest in the Python unit test framework. This article describes unittest overview, command line interface, test case automatic search, test code creation, and test suite creation methods, for more information, see
Overview
1. test fixture)
Work to be done before test preparation and after test execution, including setUp () an
): # through d[' empty '] When accessing a key that does not exist, the assertion throws Keyerror
value = d[' empty '
def test_attrerror (self):
d = Dict ()
with Self.assertraises (Attributeerror): # When accessing nonexistent key via D.empty, we expect to throw attributeerror
value = D.empty
if __ name__ = = ' __main__ ':
unittest.main ()
Just run mydict_test.py as a normal Python script.
O
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:
1.unittest Unit Test Framework file structureUnitTest is one of the Python unit test frameworks that unittest the main file structure of the test framework:File>report>all_case.py>test_case>__init__.py>test_case1 .....>public>__init__.py>login.py>loginout.pyTest_case folder primarily stores test cases, and test case naming begins with Test_The public folder is a
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
entire scriptThird, Python direct operation mode1. The above method can only execute the contents of the unit test framework, is not the output of the test report, if you want to output the test report, can be run in a non-unittest mode, that is, directly run with Python2. In the top right corner, tap open: Edit configurations2. Expand Python and
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.