杭州外贸建站,网站建设与维护大作业,wordpress导航点不开分类,深圳网站制作哪家专业测试套件#xff08;Test Suite#xff09;是测试用例、测试套件或两者的集合#xff0c;用于组装一组要运行的测试#xff08;多个测试用例集合在一起#xff09;。
#xff08;1#xff09;创建一个测试套件#xff1a;
import unittest
suite unittest.TestSuite…测试套件Test Suite是测试用例、测试套件或两者的集合用于组装一组要运行的测试多个测试用例集合在一起。
1创建一个测试套件
import unittest
suite unittest.TestSuite()2将测试用例加载到测试套件中。
1、通过模块或测试用例类加载
import testcases # 测试用例的模块
import unittest
suite unittest.TestSuite() # 创建测试套件
loader unittest.TestLoader() # 用来加载TestCase到TestSuite中的
suite.addTest(loader.loadTestsFromModuletestcases# 模块加载
suite.addTest(loader.loadTestsFromTestCase(testcases.类名)) # 用例类加载添加单条测试用例
suite.addTest(类名(用例方法名))指定测试用例的所在的目录路径
进行加载
discover(start_dir,pattern test*.py”,top_level_dir None)start_dir:待测试的模块名或测试用例目录pattern test*.py”测试用例文件名的匹配原则top_level_dir None:测试模块的顶层目录默认None。 import unittest
suite unittest.TestSuite()
loader unittest.TestLoader()
suite.addTest(loader.discover(r用例文件所在的目录的绝对路径))2、Test Runner
Test Runner用于协调测试的执行并通过图形界面、文本界面、返回特殊值向用户提供结果。
1测试结果
.用例通过
E表示代码出错了
F表示不通过
2使用启动器执行测试套件。
runner unittest.TextTestRunner() # 测试运行程序---用来执行测试用例的
runner.run(suite)3、生成测试报告
1text类型报告
with open“test_report.txt,w) as f:runner unittest.TextTestRunner(f)runner.run(suite)32html类型报告
from HTMLTestRunnerNew import HTMLTestRunner
runner HTMLTestRunner(streamopen(test_report.html, wb), # 打开一个报告文件将句柄传给streamtesterxxx, # 报告种显示的测试人员description测试报告描述, # 报告种显示描述信息title测试报告标题) # 报告的标题
# 方法2
with open(test_report.html,wb) as file:runner HTMLTestRunner(streamfile,tester xxxx, # 报告种显示的测试人员title测试报告标题, # 报告的标题description测试报告描述 ) # 报告种显示描述信息runner.run(suite)完整代码为 import time
import os
import unittest
from com.contants import CASE_DIR # 测试用例模块路径
from com.contants import REPORT_DIR # 测试报告路径
from com.myconf import conf # 读取配置文件测试报告配置信息
from library.HTMLTestRunnerNew import HTMLTestRunner # 生成测试报告
from com.sendemail import send_email
# 1.创建测试套件
suite unittest.TestSuite()
# 2. 加载TestCase到TestSuite中
# 创建对象加载
loader unittest.TestLoader()
# # 1通过模块加载
# suite.addTest(loader.loadTestsFromModule(test_case))
# # 2通过测试用例类加载
# suite.addTest(loader.loadTestsFromTestCae(test_case.类名))
#
# # 3添加单条测试用例不需要loader对象方法
# # 注意:通过用例类去创建测试用例对象时需传入用例的方法名字符串类型
# suite.addTest(类名(用例方法名))
# 4指定测试用例的所在的目录路径进行加载
suite.addTest(loader.discover(CASE_DIR))
# 测试运行程序---用来执行测试用例的
# 方法1
# runner unittest.TextTestRunner()
# 方法2将HTMLTestRunner文件放在scripts
report_name time.strftime(%Y-%m-%d %H_%M) conf.get(report,reportname)
report_path os.path.join(REPORT_DIR,report_name)
with open(report_path,wb) as file:runner HTMLTestRunner(streamfile, # 文件名tester conf.get(report,tester), # 报告种显示的测试人员title time.strftime(%Y-%m-%d %H_%M_%S) conf.get(report,title), # 报告的标题descriptionconf.get(report,description) ) # 报告种显示描述信息runner.run(suite)
# 发送测试报告
send_email(report_path,report_name)最后感谢每一个认真阅读我文章的人礼尚往来总是要有的虽然不是什么很值钱的东西如果你用得到的话可以直接拿走【文末领取】 【下面是我整理的2023年最全的软件测试工程师学习知识架构体系图全套资料】 一、Python编程入门到精通
二、接口自动化项目实战 三、Web自动化项目实战
四、App自动化项目实战 五、一线大厂简历
六、测试开发DevOps体系 七、常用自动化测试工具
八、JMeter性能测试 九、总结文末尾部小惊喜
生命不息奋斗不止。每一份努力都不会被辜负只要坚持不懈终究会有回报。珍惜时间追求梦想。不忘初心砥砺前行。你的未来由你掌握
生命短暂时间宝贵我们无法预知未来会发生什么但我们可以掌握当下。珍惜每一天努力奋斗让自己变得更加强大和优秀。坚定信念执着追求成功终将属于你
只有不断地挑战自己才能不断地超越自己。坚持追求梦想勇敢前行你就会发现奋斗的过程是如此美好而值得。相信自己你一定可以做到 文章转载自: http://www.morning.hmtft.cn.gov.cn.hmtft.cn http://www.morning.sryhp.cn.gov.cn.sryhp.cn http://www.morning.xdjwh.cn.gov.cn.xdjwh.cn http://www.morning.gkjnz.cn.gov.cn.gkjnz.cn http://www.morning.ylklr.cn.gov.cn.ylklr.cn http://www.morning.srkwf.cn.gov.cn.srkwf.cn http://www.morning.pffqh.cn.gov.cn.pffqh.cn http://www.morning.tfkqc.cn.gov.cn.tfkqc.cn http://www.morning.haolipu.com.gov.cn.haolipu.com http://www.morning.mbmh.cn.gov.cn.mbmh.cn http://www.morning.fznj.cn.gov.cn.fznj.cn http://www.morning.zstry.cn.gov.cn.zstry.cn http://www.morning.wbxrl.cn.gov.cn.wbxrl.cn http://www.morning.dytqf.cn.gov.cn.dytqf.cn http://www.morning.tpfny.cn.gov.cn.tpfny.cn http://www.morning.gmjkn.cn.gov.cn.gmjkn.cn http://www.morning.yhywr.cn.gov.cn.yhywr.cn http://www.morning.kghhl.cn.gov.cn.kghhl.cn http://www.morning.ahscrl.com.gov.cn.ahscrl.com http://www.morning.sbqrm.cn.gov.cn.sbqrm.cn http://www.morning.thbqp.cn.gov.cn.thbqp.cn http://www.morning.qqhersx.com.gov.cn.qqhersx.com http://www.morning.mmhaoma.com.gov.cn.mmhaoma.com http://www.morning.rszyf.cn.gov.cn.rszyf.cn http://www.morning.bynf.cn.gov.cn.bynf.cn http://www.morning.rjtmg.cn.gov.cn.rjtmg.cn http://www.morning.gnlyq.cn.gov.cn.gnlyq.cn http://www.morning.yrjfb.cn.gov.cn.yrjfb.cn http://www.morning.lkbdy.cn.gov.cn.lkbdy.cn http://www.morning.ymwny.cn.gov.cn.ymwny.cn http://www.morning.syglx.cn.gov.cn.syglx.cn http://www.morning.phxns.cn.gov.cn.phxns.cn http://www.morning.ppghc.cn.gov.cn.ppghc.cn http://www.morning.fy974.cn.gov.cn.fy974.cn http://www.morning.hmlpn.cn.gov.cn.hmlpn.cn http://www.morning.xsrnr.cn.gov.cn.xsrnr.cn http://www.morning.yhglt.cn.gov.cn.yhglt.cn http://www.morning.xkbdx.cn.gov.cn.xkbdx.cn http://www.morning.tjjkn.cn.gov.cn.tjjkn.cn http://www.morning.qlxgc.cn.gov.cn.qlxgc.cn http://www.morning.qrcxh.cn.gov.cn.qrcxh.cn http://www.morning.rlrxh.cn.gov.cn.rlrxh.cn http://www.morning.bqmhm.cn.gov.cn.bqmhm.cn http://www.morning.gwqq.cn.gov.cn.gwqq.cn http://www.morning.dztp.cn.gov.cn.dztp.cn http://www.morning.wynqg.cn.gov.cn.wynqg.cn http://www.morning.tzrmp.cn.gov.cn.tzrmp.cn http://www.morning.kmrgl.cn.gov.cn.kmrgl.cn http://www.morning.kntsd.cn.gov.cn.kntsd.cn http://www.morning.gynkr.cn.gov.cn.gynkr.cn http://www.morning.lrzst.cn.gov.cn.lrzst.cn http://www.morning.mpxbl.cn.gov.cn.mpxbl.cn http://www.morning.qpnmd.cn.gov.cn.qpnmd.cn http://www.morning.ftmp.cn.gov.cn.ftmp.cn http://www.morning.snmth.cn.gov.cn.snmth.cn http://www.morning.qlsbz.cn.gov.cn.qlsbz.cn http://www.morning.sdamsm.com.gov.cn.sdamsm.com http://www.morning.bsqth.cn.gov.cn.bsqth.cn http://www.morning.kksjr.cn.gov.cn.kksjr.cn http://www.morning.ggmls.cn.gov.cn.ggmls.cn http://www.morning.cmldr.cn.gov.cn.cmldr.cn http://www.morning.wflsk.cn.gov.cn.wflsk.cn http://www.morning.bpmtg.cn.gov.cn.bpmtg.cn http://www.morning.pcwzb.cn.gov.cn.pcwzb.cn http://www.morning.nba1on1.com.gov.cn.nba1on1.com http://www.morning.sbrjj.cn.gov.cn.sbrjj.cn http://www.morning.qclmz.cn.gov.cn.qclmz.cn http://www.morning.hxsdh.cn.gov.cn.hxsdh.cn http://www.morning.wgxtz.cn.gov.cn.wgxtz.cn http://www.morning.kmqjx.cn.gov.cn.kmqjx.cn http://www.morning.lbhck.cn.gov.cn.lbhck.cn http://www.morning.ruyuaixuexi.com.gov.cn.ruyuaixuexi.com http://www.morning.rqnhf.cn.gov.cn.rqnhf.cn http://www.morning.mdpkf.cn.gov.cn.mdpkf.cn http://www.morning.nzhzt.cn.gov.cn.nzhzt.cn http://www.morning.ykkrg.cn.gov.cn.ykkrg.cn http://www.morning.ttcmdsg.cn.gov.cn.ttcmdsg.cn http://www.morning.rkgyx.cn.gov.cn.rkgyx.cn http://www.morning.kfstq.cn.gov.cn.kfstq.cn http://www.morning.dongyinet.cn.gov.cn.dongyinet.cn