zoukankan      html  css  js  c++  java
  • unittest 使用 HTMLTestRunner 生成测试报告

    code

    import unittest
    from HTMLTestRunner import HTMLTestRunner
    
    class Test3(unittest.TestCase):
        @classmethod
        def setUpClass(self):
            print("execute setUpClass1")
    
        @classmethod
        def tearDownClass(self):
            print("execute tearDownClass1")
    
        def setUp(self):
            print("execute setUp2")
    
        def tearDown(self):
            print("execute tearDown2")
    
        def test_one(self):
            print('execute test_one')
            self.assertTrue('FiOO'.isupper())
    
        def test_two(self):
            print('execute test_two')
    
    
    if __name__ == '__main__':
            suite = unittest.TestSuite()
            # Test3是要测试的类名,test_one是要执行的测试方法
            suite.addTest(Test3("test_one"))
            suite.addTest(Test3("test_two"))
            filename = 'result.html'
            fb = open(filename, 'wb+')
            runner = HTMLTestRunner(stream=fb, title="测试HTMLTestRunner", description="测试HTMLTestRunner")
            runner.run(suite)
            fb.close()

    测试报告

     code2

    import unittest
    from HTMLTestRunner import HTMLTestRunner
    
    class TestDemo1(unittest.TestCase):
        """测试用例说明"""
    
        def test_success1(self):
            """执行成功"""
            self.assertEqual(2 + 3, 5)
    
        @unittest.skip("skip case")
        def test_skip2(self):
            pass
    
        def test_fail3(self):
            self.assertEqual(5, 6)
    
        def test_error4(self):
            self.assertEqual(a, 6)
    
    
    class TestDemo2(unittest.TestCase):
    
        def test_success5(self):
            self.assertEqual(2 + 2, 4)
    
    
    class TestDemo3(unittest.TestCase):
    
        def test_fail6(self):
            self.assertEqual(3, 4)
    
    
    if __name__ == '__main__':
        suit = unittest.TestSuite()
        suit.addTest(TestDemo1("test_success1"))
        suit.addTest(TestDemo1("test_skip2"))
        suit.addTest(TestDemo1("test_fail3"))
        suit.addTest(TestDemo1("test_error4"))
        suit.addTest(TestDemo2("test_success5"))
        suit.addTest(TestDemo3("test_fail6"))
    
        report = "result.html"
        with(open(report, 'wb+')) as fp:
            runner = HTMLTestRunner(
                stream=fp,
                title='Seldom自动化测试报告',
                description='单元测试'
            )
            runner.run(suit)

    测试报告

  • 相关阅读:
    java正则表达式语法详解及其使用代码实例 (转)
    【SpringMVC学习09】SpringMVC与前台的json数据交互 (转)
    SpringMVC基于代码的配置方式(零配置,无web.xml)
    倒车入库操作要求
    R通过RJDBC连接外部数据库 (转)
    卡尔曼滤波——11.预测峰值
    卡尔曼滤波——10.均值漂移
    卡尔曼滤波——6.评估高斯分布
    神经网络入门——16实现一个反向传播
    神经网络入门——15反向传播
  • 原文地址:https://www.cnblogs.com/sea-stream/p/14156524.html
Copyright © 2011-2022 走看看