之前分享了一系列的文章,别离从原理,运行,断言,执行,测试套件,如何跳过用例来解说unittest,如何初始化一次,那么咱们持续分享丑陋的html测试报告。

  在之前咱们的测试报告中,咱们有测试报告,然而原生的给咱们带的比较简单,咱们要想进去丑陋的html测试报告,是否能够呢,答案是能够的,这里我展现两个丑陋的unittest的测试报告,简洁慷慨。

        github地址:https://github.com/easonhan00...

        下载后,咱们间接复制BSTestRunner.py到我的项目目录下,咱们在代码中演示下

import unittestfrom  BSTestRunner import BSTestRunnerclass TestDemo(unittest.TestCase):    def setUp(self):        pass    def tearDown(self):        pass    def testEqual(self):        self.assertEqual("12","122")def suite():    suite = unittest.TestSuite()    suite.addTests(unittest.TestLoader().loadTestsFromName("testdemoone.TestDemo"))    return suiteif __name__ == "__main__":    report="test.html"    suitone=suite()    openone= open(report,'w+')    bstest=BSTestRunner(title="演示",description="演示测试报告",stream=openone)    bstest.run(suitone)

咱们展现下 运行的后果。

上面在举荐一个产生测试报告的框架,个人感觉也很棒
开源地址:https://github.com/Testerlife...,这是有mock大佬开源。
咱们下载后间接复制BeautifulReport.py,template到我的项目门路下。创立一个门路report。咱们复制到本地所以,我略微改变了 PATH。

class PATH:    """ all file PATH meta """    config_tmp_path = os.getcwd() +'/template/template'

咱们如何组织用例呢。

import unittestfrom BeautifulReport import BeautifulReportclass TestDemo(unittest.TestCase):    def setUp(self):        pass    def tearDown(self):        pass    def testEqual(self):        self.assertEqual("12","122")def suite():    suite = unittest.TestSuite()    suite.addTests(unittest.TestLoader().loadTestsFromName("testdemoone.TestDemo"))    return suiteif __name__ == "__main__":    report = "test.html"    suitone = suite()    result = BeautifulReport(suitone)    result.report(filename='test.html', description='测试deafult报告', log_path='report')

咱们看下最初的执行的后果


新版本的还能够展现图片,大家能够联合本人的理论状况应用,应用办法能够见官网。https://github.com/Testerlife...。

大家能够依据本人的理论状况去抉择适宜本人的即可。

欢送关注我的集体公众号