套件的使用追加

方法一: 执行类下面的 测试case

if __name__ == '__main__':
suiteTest = unittest.TestSuite()
suiteTest.addTest(TestAuto("testCase_001"))
suiteTest.addTest(TestAuto("testCase_002"))
unittest.TextTestRunner(verbosity=2).run(suiteTest)

# 按照一定时间格式获取当前时间(防止测试报告覆盖)
now = time.strftime(u'%Y-%m-%d-%H-%M-%S')
# 确定生成报告的路径
report_file = "F:\\python3\\report\\" + now + "_test_report.html"
with open(report_file, 'wb') as report:
runner = HTMLTestReportCN.HTMLTestRunner(stream=report, title=u'测试报告',
description=u'如下为用例执行结果,请查阅!',
)
runner.run(suiteTest)
report.close()

 

方法二: 按测试类执行

if __name__ == '__main__':
suiteTest = unittest.TestSuite(unittest.makeSuite(TestAuto))
'''
这里的verbosity是一个选项,表示测试结果的信息复杂度,有三个值
0 (静默模式): 你只能获得总的测试用例数和总的结果 比如 总共100个 失败20 成功80
1 (默认模式): 非常类似静默模式 只是在每个成功的用例前面有个“.” 每个失败的用例前面有个 “F”
2 (详细模式):测试结果会显示每个测试用例的所有相关的信息
并且 你在命令行里加入不同的参数可以起到一样的效果
加入 –quiet 参数 等效于 verbosity=0
'''
unittest.TextTestRunner(verbosity=2).run(suiteTest)

# 按照一定时间格式获取当前时间(防止测试报告覆盖)
now = time.strftime(u'%Y-%m-%d-%H-%M-%S')
# 确定生成报告的路径
report_file = "F:\\python3\\report\\" + now + "_test_report.html"
with open(report_file, 'wb') as report:
runner = HTMLTestReportCN.HTMLTestRunner(stream=report, title=u'测试报告',
description=u'如下为用例执行结果,请查阅!',
)

runner.run(suiteTest)
report.close()

 

方法三: 执行一个文件

f __name__ == '__main__':
suiteTest = unittest.Testloader().loadTestsFromModule('seleniumtest.py')
'''
这里的verbosity是一个选项,表示测试结果的信息复杂度,有三个值
0 (静默模式): 你只能获得总的测试用例数和总的结果 比如 总共100个 失败20 成功80
1 (默认模式): 非常类似静默模式 只是在每个成功的用例前面有个“.” 每个失败的用例前面有个 “F”
2 (详细模式):测试结果会显示每个测试用例的所有相关的信息
并且 你在命令行里加入不同的参数可以起到一样的效果
加入 –quiet 参数 等效于 verbosity=0
'''
unittest.TextTestRunner(verbosity=2).run(suiteTest)

# 按照一定时间格式获取当前时间(防止测试报告覆盖)
now = time.strftime(u'%Y-%m-%d-%H-%M-%S')
# 确定生成报告的路径
report_file = "F:\\python3\\report\\" + now + "_test_report.html"
with open(report_file, 'wb') as report:
runner = HTMLTestReportCN.HTMLTestRunner(stream=report, title=u'测试报告',
description=u'如下为用例执行结果,请查阅!',
)

runner.run(suiteTest)
report.close()

 

来源: https://mp.weixin.qq.com/s/MiwG6jXCCnTl5Y2FhJTPVg

posted @ 2020-05-14 10:55  凯宾斯基  阅读(181)  评论(1编辑  收藏  举报