Unit testing plays an important role in ensuring development efficiency, maintainability and software quality, so-called unit testing is a test method for correctness detection of a class, a module or a function.Here are some of the learning notes that are done by using Python + unitest as a unit test.UnitTest provides test cases, test suites, test Fixtures,test Runner:
Test Case: By inheriting the TestCase class, we can create a test, or a s
ObjectiveWhen we write a use case, the use case of a single script executes well, so how do you batch execute multiple scripts? This is the time to use the Discover method inside the Unittet to load the use case. After loading the use case, use the Run method of the Texttestrunner class inside the UnitTest to execute multiple scripts at once.First, the new test project1.pycharm upper left corner file>new projetc>pure
The assert statement is also available in C or C ++. Short assertions. The following is a description from Python help document:
Assert statements are a convenient way to insert debugging assertions into a program:
An assert statement is used to insert a debugging breakpointProgramIs a convenient way.
Format o
This paper completes Appium automated test based on Python unit test framework unittest, and generates a visual test report based on HTML.code example:1 #利用unittest并生成测试报告2 classappium_test (unittest. TestCase):3 """Appium Test Class"""4 def setUp (self):5Desired_caps = {6 'PlatformName':'Android',7
!-executing the test case 02-end!start!-executing the test case 03-end!2. A few points can be seen from the implementation results--the predecessor Setup executed first, then the use case (test*) executed, and the last executed post teardown--The execution order of test cases (test*) is performed according to 01-02-03, that is, according to the use case name to execute sequentially--addtest (self) This method does not execute, stating that only the use case at the beginning of testIv. Examples o
Python has a module with a unit test inside it, and pyunit is what we say:UnitTestFirst, introduce the basic use of the next unittest:1.import UnitTest2. Define an inherited from UnitTest. Test Case Classes for TestCase3. Define setup and teardown, and do some ancillary work before and after each test case.4. Define the test case, with the name beginning with tes
1. Problem: After using both the UnitTest framework and the Htmlreport framework in the same. py file in Python, Htmlreport is not executed.2, why? actually not htmlreport not be executed, also not htmlreport not generate test report, is because if __name__ = = ' __main__ ' code at all did not execute well!3. The source of the solution: because I didn't write print statements in my main code at first. Did n
Do the development of friends in writing code at the same time generally will write test code, which for the students to do operation and maintenance is seldom used.Today we will write the test code, using the UnitTest module.Cat test.pyImport UnitTestdef isodd (n):return n% 2 = = 1Class Isoddtests (UnitTest. TestCase):def setUp (self):Print "Test start ....."---"def tearDown (self):Print "Test end ......"d
The last is a small exercise, this time will be unittest modular, that is, the use case is placed in the case directory, start placed under the Bin directory-------------------Start------------------------------Import Unittest,htmltestrunner# 1x. First search through Testloader for files ending with. py# 2. Recycle and add each test to the suite# 3. Run this collection to generate a test reportSuite =
ObjectiveAfter executing the use case in bulk, the generated test report is text-less intuitive and, in order to better demonstrate the test report, it is best to generate HTML format.UnitTest inside is unable to generate HTML format report, need to import a third-party module: HtmltestrunnerFirst, import Htmltestrunner1. This module download can not be installed through PIP, can only be downloaded and then manually imported: http://tungwaiyip.info/software/HTMLTestRunner.html2.Download The html
A tutorial on building a framework recently http://blog.csdn.net/u011541946/article/category/6788788AddtestYou can load different test functions within the same class.#coding = Utf-8ImportUnitTestImporttestsuites fromTestsuites.test_baidu_searchImportBaidusearch fromTestsuites.test_get_page_titleImportGetpagetitle Suite=UnitTest. TestSuite () suite.addtest (Baidusearch ('Test_baidu_search')) Suite.addtest (Baidusearch ('TEST_SEARCH2')) Suite.addtest (
Friends who have used python assert should often encounter such doubts, such as:(A, b) = (1, ' 1 ')Assert A==b # Error:assertionerrorWhen debugging code, it's hard to see why it's wrong, unless it's written like this:Assert 1== ' 1 ', "fact==expect, [fact]=%s, [expect]=%s"% ([a],[b]) # assertionerror:fact==expect, [fact]=[1], [expect] =[' 1 ']But so every time to
When we use Python's unittest for automation or unit testing, sometimes a test case needs to be executed several times depending on the combination of input and output, but a use case in UnitTest can only have one set of parameter combinations, and if you use a circular approach, In the generated test report there will be only one test case statistics, the fact that we need a set of parameters to be counted
Uinittest use UnitTest. TestCaseInstance:import unittestclass Test1(unittest.TestCase): def test_x1(self): self.a=1 def test_x2(self): print("a:",self.a)class Test2(): def x1(self): self.b=1 def x2(self): print("b:",self.b)#测试调用1unittest.main()#测试调用2A=Test2()A.x1()A.x2()
First UnitTest. The test case method in TestCase needs to start with test, and subsequent
--------------- -------------------------------------------------------Ran 12 tests in 12.001s 4. Note that the order of execution here is to execute 0,1 first, then execute 10,11,12 in turn, do not ask me why, do not find me to solve, design so, before the DDT framework has the same problem.5. In addition to the dictionary parameters, the type of the meta-group is also possible@paramunittest. parametrized ("Admin","123","true"), ("Admin1","123","true"), ("Admin2","123","true"), ("Admin3
!"@classmethoddef teardownclass (CLS):Time.sleep (1)Print "end!"def test01 (self):Print "Execute test Case 01"def test03 (self):Print "Execute test case 03"def test02 (self):Print "Execute test case 02"def addtest (self):Print "Add Method"if __name__ = = "__main__":Unittest.main ()2. From the execution results it can be seen that the predecessor and the post are executed only once prior to the execution of the use case.start!Execute test Case 01Execute test Case 02Execute test Case 03... end!---
, b) TD style= "PADDING:2PX 5px; border-width:1px 1px 1px 0px; Border-style:solid; Border-color:rgb (221,221,221); Background-color:rgb (238,238,255) ">
a in b
2.7
assertnotin (A, b)
a not in b
2.7
assertisinstance (A, b)
isinstance (A, b)
2.7
assertnotisinstance (A, b)
not isinstance (A, b)
2.7
5. Call the Unittest.main () method to run all methods that begin with
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.