Python HTMLTestRunner报告及BeautifulReport报告

import unittest
import HTMLTestRunner

class Testfunc(unittest.TestCase):
    def testa(self):
        """testa测试用例1"""
        self.assertEqual(first=1, second=1, msg='first!=second时打印错误信息')

    def testb(self):
        """testb测试用例2"""
        self.assertIn(member='a', container='abcd', msg='member不在container中打印此信息')

    def testc(self):
        """testc测试用例2"""
        self.assertGreater(a=1, b=1, msg='a<=b打印此错误信息')


# if __name__ == "__main__":
#     unittest.main()

suit = unittest.TestSuite()
suit.addTest(unittest.makeSuite(Testfunc))
suit.addTest(Testfunc('testa'))
# unittest.TextTestRunner().run(suit)

f = open('测试.html', 'wb')
report = HTMLTestRunner.HTMLTestRunner(stream=f, title='自动化测试练习', description='HTMLTestRunner报告')
report.run(suit)

测试报告如下: 

Python HTMLTestRunner报告及BeautifulReport报告_第1张图片

 结合discover,使用HTMLTestRunner

import unittest
import HTMLTestRunner

def createsuit():
    testdir = "E:/lw/书籍/python/自动化/day1/"

    discover = unittest.defaultTestLoader.discover(testdir,pattern="test*.py",top_level_dir=None)
    print(discover)

    return discover

if __name__ == '__main__':
    # runner = unittest.TextTestRunner()
    # runner.run(createsuit())
    fp = open('E:/lw/书籍/python/自动化/day1/1.html', mode='wb')
    runner = HTMLTestRunner.HTMLTestRunner(stream=fp,title='test',description='hahaha')
    testsuit = createsuit()
    runner.run(testsuit)

 

from BeautifulReport import BeautifulReport as bf
suit = unittest.TestSuite()
suit.addTest(unittest.makeSuite(Testfunc))
suit.addTest(Testfunc('testa'))
# unittest.TextTestRunner().run(suit)

r = bf(suit)
r.report(description='BeautifulReport练习', filename='bf.html')

Python HTMLTestRunner报告及BeautifulReport报告_第2张图片

 

转载于:https://www.cnblogs.com/xinjing-jingxin/p/9153348.html

你可能感兴趣的:(Python HTMLTestRunner报告及BeautifulReport报告)