htmltestrunner--Interface Test Report Example

Source: Internet
Author: User
Tags urlencode

1. The test code is as follows python3.5

ImportOSImportUnittest,json,htmltestrunner fromUrllibImportrequest, ParseclassTestbdapi (unittest. TestCase):defSetUp (self):#If you do not need each case to pre-set and clean up the environment, but each class used once, just need to use SetupClass, Teardownclass instead, if the entire file only need to use once, then use to use Setupmodule () and Teardownmodule () These two functions, note is the function, and the TestCase class siblingURL ="Http://fanyi.baidu.com/v2transapi"    deftestapi1 (self): headers={        "user-agent":"mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/44.0.2403.155 safari/537.36"} params= {        " from":"en",        " to":"ZH",        "Query":"Hotel" #Enquiry} URL="Http://fanyi.baidu.com/v2transapi"params=parse.urlencode (params). Encode ('Utf-8') R= Request. Request (URL, headers=headers, data=params) page=Request.urlopen (R). Read () RS=json.loads (Page.decode ('UTF8'))        assertU'Hotel' inchSs:'Trans_result']['Data'][0]['DST']    deftestapi2 (self): headers={        "user-agent":"mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/44.0.2403.155 safari/537.36"} params= {        " from":"en",        " to":"ZH",        "Query":" Hot" #} URL="Http://fanyi.baidu.com/v2transapi"params=parse.urlencode (params). Encode ('Utf-8') R= Request. Request (URL, headers=headers, data=params) page=Request.urlopen (R). Read ()#return pageRs=json.loads (Page.decode ('UTF8'))        assertU'Hotel' inchrs['Trans_result']['Data'][0]['DST']    defTearDown (self):Pass    if __name__=='__main__': Path= R'test.html'Open_sys= Open (Path,'WB')    #to execute a use case for an entire classSuite=UnitTest. Testloader (). Loadtestsfromtestcase (TESTBDAPI)#execute a use case    #define a Test ContainerTest =UnitTest. TestSuite ()#Adding test cases to the test ContainerTest.addtest (Testbdapi ("testapi1")) Test.addtest (Testbdapi ("Testapi2")) Runner=Htmltestrunner.htmltestrunner (Stream=open_sys,#Open Write StreamTitle=u'Baidu Translation API Interface test report', Description=u'Interface Test Details'    )    #runner.run (test)Runner.run (Suite)#write use case execution resultsOpen_sys.close ()#Close Write StreamOs.system ('Start test.html')#Open HTML Report    
HTML Report Code

2. Place the htmltestrunner.py under Lib in the Python installation directory

python3.* version, python2.* version

htmltestrunner--Interface Test Report Example

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.