Python-unittest Study 2

Source: Internet
Author: User

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

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.