关于测试自动化:unittest系统七产生漂亮的测试报告

4次阅读

共计 1577 个字符,预计需要花费 4 分钟才能阅读完成。

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

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

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

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

import unittest
from  BSTestRunner import BSTestRunner

class 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 suite

if __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 unittest
from BeautifulReport import BeautifulReport

class 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 suite
if __name__ == "__main__":
    report = "test.html"
    suitone = suite()
    result = BeautifulReport(suitone)
    result.report(filename='test.html', description='测试 deafult 报告', log_path='report')

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


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

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

欢送关注我的集体公众号

正文完
 0