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 report
Suite = UnitTest. TestSuite () #切记此处加括号
All_case = Unittest.defaultTestLoader.discover (
R ' E:\code\jxz-liuzunchang-code\day11\new_ Cancer _liu\ watch video notes 2\auto\case ', ' *.py '
)
#定义测试集合, find all the case under case. PY file
# Print (all_case)
For case in All_case:
Print (' Case ... ', case)
Suite.addtests (case) #括号中必须是一个测试套件, here the class is already a py file with the following sentence is different
# suite.addtest (Unittest.makesuite (My2)) # All test Cases under the import class this is in class, so you need to use the Makesuite
FW = open (' report_l.html ', ' WB ')
Runner = Htmltestrunner.htmltestrunner (stream=fw,title= ' kkk2test ', description= ' Miaoshu ')
Runner.run (Suite)
-------------------Case----------------
Import UnitTest
Class XXX (unittest. TestCase):
def test_chxxx (self):
"This is xxx use case '"
Self.assertequal (a)
Python-unittest Study 2