unittest几种执行测试用例的方法

1.使用unittest.mail()

 

2.使用testsuit执行  

  suite = unittest.TestSuite()
  suite.addTest(UCTestCase("test1"))
  suite.addTest(UCTestCase("test2"))
  runner = unittest.TextTestRunner()
  runner.run(suite)


3.使用testLoader

  suite1 = unittest.TestLoader().loadTestsFromTestCase(TestCase1)
  suite2 = unittest.TestLoader().loadTestsFromTestCase(TestCase2)
  suite = unittest.TestSuite([suite1, suite2])
  unittest.TextTestRunner(verbosity=2).run(suite)

4.通过discover方式加载某路径下的所有测试用例

test_dir = './TestCase'
suite = unittest.defaultTestLoader.discover(start_dir=test_dir,pattern='Test*.py')
runner=unittest.TextTestRunner() 
runner.run(discover)

5.将断言报告写入文件中

with open(" ","w+",encoding='utf-8') as file

unittest.TextTestRunner(stream=file,verbosity=2)#0 1 2 2是最详细的 

6.优化报告:HTMLTextRunner()

with open(reportname,'wb')as f:
runner = HTMLTestRunner.HTMLTestRunner(
stream=f,
title="测试报告",
description="测试导入testcase"
)
runner.run(suite)


posted @ 2020-07-10 16:09  mmmm3  阅读(638)  评论(0编辑  收藏  举报