zoukankan      html  css  js  c++  java
  • Unittest方法 -- 测试报告&加载测试类(discover)

    import unittest
    import HTMLTestRunner
    import os

    class F11(unittest.TestCase):
    def test_001(self):
    self.assertEqual(1,1)

    def test_002(self):
    self.assertEqual(1,1)

    class F12(unittest.TestCase):
    def test_f11_001(self):
    self.assertEqual(1,1)

    def test_f11_002(self):
    self.assertEqual(1,1)

    def test_f11_003(self):
    self.assertEqual(1,1)

    @staticmethod
    def suite():
    suites = unittest.TestLoader().discover(
    start_dir = os.path.dirname(__file__),
    pattern = "test_report.py",
    top_level_dir = None
    )
    return suites

    if __name__ == '__main__':
    suite = unittest.makeSuite(F11)
    filename = "recort.html"
    fp = open(filename,"wb")
    runner = HTMLTestRunner.HTMLTestRunner(fp,title="",description="")
    runner.run(suite)


    #使用HTML生成测试报告
    file = open("report.html","wb")
    runner = HTMLTestRunner.HTMLTestRunner(
    stream = file,
    title = "测试数据",
    description=""
    )
    runner.run(F12())
    file.close()

    #使用discover套件可以执行指定文件的脚本!
    suite = unittest.TestLoader().discover(
    start_dir = os.path.dirname(__file__),
    pattern = "test_report.py",
    top_level_dir=None
    )
    unittest.TextTestRunner(verbosity=2).run(suite)

    """执行F11脚本的三种套件方法"""
    suite = unittest.TestLoader().loadTestsFromModule("test_report.py")
    unittest.TextTestRunner(verbosity=2).run(suite)

    suite = unittest.TestLoader().loadTestsFromTestCase(F11)
    unittest.TextTestRunner(verbosity=2).run(suite)

    suite = unittest.TestSuite(unittest.makeSuite(F11))
    unittest.TextTestRunner(verbosity=2).run(suite)




  • 相关阅读:
    Eclipse添加jsp页面后引入java指令报错解决方法
    Spring使用RowMapper将数据中的每一行封装成用户定义的类
    Spring使用jdbcJdbcTemplate和三种方法配置数据源
    下载windows版本apache网页服务器
    配置tomcat-users
    找到MySQL配置文件默认路径
    网络爬虫技术
    爬虫具体问题
    分布式爬虫调度策略
    爬虫进阶
  • 原文地址:https://www.cnblogs.com/Teachertao/p/11183554.html
Copyright © 2011-2022 走看看