zoukankan      html  css  js  c++  java
  • python---利用unittestreport模块输出测试报告

    一、安装unittestreport

    pip install unittestreport

    具体使用方法:https://github.com/musen123/UnitTestReport

    二、 具体实例参考用法

     1 #coding:utf-8
     2 import unittest
     3 from unittestreport import TestRunner
     4 import os
     5 class Counter(unittest.TestCase):
     6 
     7     def setUp(self):
     8         self.a = 5
     9         self.b = 3
    10         self.c = 0 
    11     def test_add(self):
    12         self.c = self.a + self.b
    13         self.assertEqual(self.c,8)
    14     def test_sub(self):
    15         self.c = self.a - self.b
    16         self.assertEqual(self.c,2)
    17     @unittest.skip("跳过测试用例test_mulyiply")
    18     def test_multiply(self):
    19         self.c = self.a * self.b
    20         self.assertEqual(self.c,15)
    21     def test_integer(self):
    22         self.c = self.a % self.b
    23         self.assertEqual(self.c,1)
    24     def tearDown(self):
    25         pass
    26 
    27 #利用unittest中的TestSuite模块构造测试集
    28 suite = unittest.TestSuite()
    29 suite.addTest(Counter("test_add"))
    30 suite.addTest(Counter("test_sub"))
    31 suite.addTest(Counter("test_multiply"))
    32 suite.addTest(Counter("test_integer"))
    33 
    34 BasePath = os.path.dirname(__file__)#获取当前文件所在路径
    3536 if __name__ == "__main__":
    37     fp = BasePath + "\report" #特别需要注意的是 report文件是已存在的,否则会报错
    38     #filename为文件名称,report_dir报告输出位置,title测试标题,tester测试测试人员,desc描述
    39     runner = TestRunner(suite,filename="report.html",report_dir=fp,title="测试报告",tester="LLEI",desc="LLEI执行的测试用例")
    40     runner.run()

    输出html如图效果,一目了然,简单实用

     
  • 相关阅读:
    Leetcode--Median of Two Sorted Arrays
    My rule
    00113_通过反射获取成员方法并使用
    雷林鹏分享:MySQL 管理
    雷林鹏分享:MySQL 安装
    雷林鹏分享:MySQL 教程
    雷林鹏分享:jQuery Mobile 列表视图
    雷林鹏分享:jQuery Mobile 网格
    雷林鹏分享:MySQL 导出数据
    雷林鹏分享:MySQL 导入数据
  • 原文地址:https://www.cnblogs.com/liaolei123/p/13476958.html
Copyright © 2011-2022 走看看