zoukankan      html  css  js  c++  java
  • unitest中HTML测试报告的优化

    简介:

    为每一个测试用例添加说明,那么将会使测试报告更加易读,工作中汇报数据的技巧

    其实就是添加u“msg”即可

    # -*- coding:UTF-8 -*-
    __autor__ = 'zhouli'
    __date__ = '2018/11/10 21:37'
    
    import unittest
    import HTMLTestRunner
    import time
    
    
    class UserTestCase(unittest.TestCase):
        def setUp(self):
            self.age = 25
            self.name = "呦西,开始了"
            print('setup method------')
    
        def tearDown(self):
            print("--tearDown method------")
    
        def test_one(self):
            print("test_one 周先生来了")
            self.assertEqual(self.name, "呦西,开始了", msg="口令不对!")
    
        def test_two(self):
            print('test_two')
            self.assertFalse("zl".isupper(), msg="不是大写")
    
        def test_three(self):
            print('test_three')
            self.assertEqual(self.age, 25)
    
        def test_four(self):
            u"第四个函数"
            print('test_four')
            self.assertEqual(self.age, 25)
    
    
    if __name__ == '__main__':
        suite = unittest.TestSuite()
        suite.addTest(UserTestCase("test_one"))  # 测试类名加方法
        suite.addTest(UserTestCase("test_four"))
        suite.addTest(UserTestCase("test_two"))
        suite.addTest(UserTestCase("test_three"))
    
        # verbosity参数可以控制执行结果的输出, 0是简单报告,1是一般报告, 2是详细报告 默认1 会在每个成功的用例前面有个“.”每个失败用例前面有个“F”
        # runner = unittest.TextTestRunner(verbosity=0)
        # runner.run(suite)
        file_prefix = time.strftime("%Y-%m-%d", time.localtime())
        print(file_prefix)
        with open("./" + file_prefix + "_result.html", "wb") as f:
            runner = HTMLTestRunner.HTMLTestRunner(stream=f, title=u"zl测试", description=u"执行情况")
            runner.run(suite)

    没有过不去的坎,只有没加够的油!
  • 相关阅读:
    Keepalived 无法自动转换主备角色,请关注 iptables 防火墙配置
    Linux 下使用网易的SMTP服务器 发送邮件
    Spring-boot 最小demo
    go build 时报错 cc1.exe: sorry, unimplemented: 64-bit mode not compiled in
    spark-shell 执行脚本并传入参数
    JVM
    spark
    spark
    linux
    linux
  • 原文地址:https://www.cnblogs.com/zhoulixiansen/p/9943115.html
Copyright © 2011-2022 走看看