当前位置: 首页 > news >正文

广州网站建设公司万齐网络科技网络推广费用

广州网站建设公司万齐网络科技,网络推广费用,vultr服务器做网站,seo博客模板目录 一、unittest框架基本介绍二、unittest框架解析三、unittest框架使用方法1.测试固件2.测试套件3.用例的执行顺序4.忽略测试用例中的方法5.unittest断言6.HTML报告生成 一、unittest框架基本介绍 在进行selenium IDE脚本录制导出的脚本中#xff0c;我们发现其中多了很多… 目录 一、unittest框架基本介绍二、unittest框架解析三、unittest框架使用方法1.测试固件2.测试套件3.用例的执行顺序4.忽略测试用例中的方法5.unittest断言6.HTML报告生成 一、unittest框架基本介绍 在进行selenium IDE脚本录制导出的脚本中我们发现其中多了很多代码这些代码正是unittest测试框架。unittest 是web界面的功能测试框架白盒测试测试框架是Junit。unittest 单元测试提供了创建测试用例、测试套件以及批量执行的方案。unittest 在安装python 以后就直接自带了调用import unittest 就可以使用。 二、unittest框架解析 1.test fixture测试固件存了类里面固定的方法初始化和清理测试环境比如创建临时的数据库文件和目录等 2.test case单元测试用例TestCase 是编写单元测试用例最常用的类 3.test suite测试套件把测试方法放到容器里单元测试用例的集合TestSuite 是最常用的类 4.test runner执行单元测试 5.test report生成测试报告 三、unittest框架使用方法 1.测试固件 一个方法一个方法的去写。 setup进行初始化 teardown 进行清理 Self 代表实例 Class 继承父类 from selenium import webdriver import unittest import time from selenium.common.exceptions import NoAlertPresentException from selenium.webdriver.common.by import By#setup和teardown在每次运行test_程序之前和之后都会默认运行 class testCase1(unittest.TestCase):#初始化def setUp(self):self.driver webdriver.Chrome()self.url http://www.baidu.com/self.driver.get(self.url)time.sleep(3)self.driver.maximize_window()time.sleep(3)#关闭以及清理def tearDown(self):self.driver.quit()#自动默认运行前面加test_def test_baidu1(self):driver self.driverdriver.find_element(By.ID, kw).send_keys(星黛露)driver.find_element(By.ID, su).click()time.sleep(3)#调用才使用def is_alert_exist(self):try:self.driver.switch_to.alertexcept NoAlertPresentException as e:return Falsereturn Trueif __name__ __main__ :unittest.main(verbosity0)2.测试套件 测试套件通俗来讲就是存放测试用例测试方法的一个容器。 1类里面一个方法一个方法添加 test001和test002都是文件testCase1和testCase2是文件里的类可以称之为测试用例test_baidu1和test_baidu2是类里的方法。 Addtest import unittest from src0303 import test001, test002#创建一个测试套件 def createsuite():suiteunittest.TestSuite()suite.addTest(test001.testCase1(test_baidu1))suite.addTest(test002.testCase2(test_baidu1))return suiteif __name__ __main__:suite createsuite()runner unittest.TextTestRunner(verbosity2)runner.run(suite)2一个类一个类的添加 makeSuite()只是添加文件里的类类里的方法不用一个一个的添加。 import unittest from src0303 import test001, test002def createsuite():suiteunittest.TestSuite()suite.addTest(unittest.makeSuite(test001.testCase1))suite.addTest(unittest.makeSuite(test001.testCase2))return suiteif __name__ __main__:suite createsuite()runner unittest.TextTestRunner(verbosity1)runner.run(suite)3 一个文件一个文件的测试 适用于文件非常多的时候文件要是一定格式命名的。 discover() #src202201文件夹找到test00*.py开头的文件夹 import unittest def createSuite():discoverunittest.defaultTestLoader.discover(../src202201,patterntest00*.py,top_level_dirNone)if __name____main__:suite createsuite()runner unittest.TextTestRunner(verbosity1)runner.run(suite)注Verbosity1或者2表示打印方法很详细如下: 3.用例的执行顺序 unittest框架(文件名类名方法名-)默认加载测试用例的顺序是根据ASCII码的顺序数字与字母的顺序为:0-9,A-Z,a-z。例如Testadd比Testade优先执行。 4.忽略测试用例中的方法 适用于书写方法太多但是只想执行少数测试用例的情况。在想忽略的方法前加标签。 unittest.skip(skipping)5.unittest断言 1断言概念 断言是为了判断实际和预期结果是否一致。自动化的测试中 对于每个单独的case来说一个case的执行结果中 必然会有期望结果与实际结果 来判断该case是通过还是失败 在unittest 的库中提供了大量的实用方法来检查预期值与实际值 来验证case的结果 一般来说 检查条件大体分为等价性 逻辑比较以及其他 如果给定的断言通过 测试会继续执行到下一行的代码 如果断言失败 对应的case测试会立即停止或者生成错误信息( 一般打印错误信息即可) 但是不要影响其他的case执行。 2常用断言方法 断言方法断言描述assertEqual(arg1, arg2, msgNone)验证arg1arg2不等则failassertNotEqual(arg1, arg2, msgNone)验证arg1 ! arg2, 相等则failassertTrue(expr, msgNone)验证expr是true如果为false则failassertFalse(expr,msgNone)验证expr是false如果为true则failassertIs(arg1, arg2, msgNone)验证arg1、arg2是同一个对象不是则failassertIsNot(arg1, arg2, msgNone)验证arg1、arg2不是同一个对象是则failassertIsNone(expr, msgNone)验证expr是None不是则failassertIsNotNone(expr, msgNone)验证expr不是None是则failassertIn(arg1, arg2, msgNone)验证arg1是arg2的子串不是则failassertIn(arg1, arg2, msgNone)验证arg1不是arg2的子串是则failassertIsInstance(obj, cls, msgNone)验证obj是cls的实例不是则failassertNotIsInstance(obj, cls,msgNone)验证obj不是cls的实例是则fail以第一个断言举例 class testCase1(unittest.TestCase):#初始化def setUp(self):self.driver webdriver.Chrome()self.url http://www.baidu.com/self.driver.get(self.url)time.sleep(3)self.driver.maximize_window()time.sleep(3)#关闭以及清理def tearDown(self):self.driver.quit()#自动默认运行前面加test_def test_baidu1(self):driver self.driverdriver.find_element(By.ID, kw).send_keys(星黛露)driver.find_element(By.ID, su).click()time.sleep(3)#判断title(星黛露的百度搜索)与星黛露_百度搜索是否相同若不相同输出“not equal”并调用is_alert_exist(self)报异常此处是相等的。self.assertEqual(driver.title,星黛露_百度搜索,msgnot equal!)#调用才使用def is_alert_exist(self):try:self.driver.switch_to.alertexcept NoAlertPresentException as e:return Falsereturn Trueif __name__ __main__ :unittest.main(verbosity0)6.HTML报告生成 将控制台结果整理成结果涉及失败的原因和结果。将HTMLTestRunner.py放到安装python的lib文件夹里。 未完待更新…
文章转载自:
http://www.morning.dbqg.cn.gov.cn.dbqg.cn
http://www.morning.c7491.cn.gov.cn.c7491.cn
http://www.morning.qrmyd.cn.gov.cn.qrmyd.cn
http://www.morning.byxs.cn.gov.cn.byxs.cn
http://www.morning.gynkr.cn.gov.cn.gynkr.cn
http://www.morning.yqrfn.cn.gov.cn.yqrfn.cn
http://www.morning.qxwgx.cn.gov.cn.qxwgx.cn
http://www.morning.gfrjs.cn.gov.cn.gfrjs.cn
http://www.morning.hxfrd.cn.gov.cn.hxfrd.cn
http://www.morning.kndst.cn.gov.cn.kndst.cn
http://www.morning.xjnjb.cn.gov.cn.xjnjb.cn
http://www.morning.fslxc.cn.gov.cn.fslxc.cn
http://www.morning.fosfox.com.gov.cn.fosfox.com
http://www.morning.bkppb.cn.gov.cn.bkppb.cn
http://www.morning.pmptm.cn.gov.cn.pmptm.cn
http://www.morning.cttgj.cn.gov.cn.cttgj.cn
http://www.morning.mwqbp.cn.gov.cn.mwqbp.cn
http://www.morning.jlpdc.cn.gov.cn.jlpdc.cn
http://www.morning.gnkdp.cn.gov.cn.gnkdp.cn
http://www.morning.rqnhf.cn.gov.cn.rqnhf.cn
http://www.morning.bkxnp.cn.gov.cn.bkxnp.cn
http://www.morning.ryqsq.cn.gov.cn.ryqsq.cn
http://www.morning.rdlxh.cn.gov.cn.rdlxh.cn
http://www.morning.hrdx.cn.gov.cn.hrdx.cn
http://www.morning.lpsjs.com.gov.cn.lpsjs.com
http://www.morning.fwgnq.cn.gov.cn.fwgnq.cn
http://www.morning.zmwd.cn.gov.cn.zmwd.cn
http://www.morning.rnfn.cn.gov.cn.rnfn.cn
http://www.morning.psxwc.cn.gov.cn.psxwc.cn
http://www.morning.yubkwd.cn.gov.cn.yubkwd.cn
http://www.morning.mwbqk.cn.gov.cn.mwbqk.cn
http://www.morning.yqqxj26.cn.gov.cn.yqqxj26.cn
http://www.morning.wfwqr.cn.gov.cn.wfwqr.cn
http://www.morning.lyhry.cn.gov.cn.lyhry.cn
http://www.morning.bhjyh.cn.gov.cn.bhjyh.cn
http://www.morning.kbbmj.cn.gov.cn.kbbmj.cn
http://www.morning.zrgdd.cn.gov.cn.zrgdd.cn
http://www.morning.chrbp.cn.gov.cn.chrbp.cn
http://www.morning.bpmnc.cn.gov.cn.bpmnc.cn
http://www.morning.clwhf.cn.gov.cn.clwhf.cn
http://www.morning.zlrsy.cn.gov.cn.zlrsy.cn
http://www.morning.qwmdx.cn.gov.cn.qwmdx.cn
http://www.morning.hpkgm.cn.gov.cn.hpkgm.cn
http://www.morning.skbbt.cn.gov.cn.skbbt.cn
http://www.morning.rlzxr.cn.gov.cn.rlzxr.cn
http://www.morning.rrhfy.cn.gov.cn.rrhfy.cn
http://www.morning.xpzkr.cn.gov.cn.xpzkr.cn
http://www.morning.rjfr.cn.gov.cn.rjfr.cn
http://www.morning.xqwq.cn.gov.cn.xqwq.cn
http://www.morning.gxeqedd.cn.gov.cn.gxeqedd.cn
http://www.morning.fyzsq.cn.gov.cn.fyzsq.cn
http://www.morning.stlgg.cn.gov.cn.stlgg.cn
http://www.morning.xxrwp.cn.gov.cn.xxrwp.cn
http://www.morning.qdscb.cn.gov.cn.qdscb.cn
http://www.morning.nqbkb.cn.gov.cn.nqbkb.cn
http://www.morning.qbzdj.cn.gov.cn.qbzdj.cn
http://www.morning.ykswq.cn.gov.cn.ykswq.cn
http://www.morning.bzfld.cn.gov.cn.bzfld.cn
http://www.morning.vjwkb.cn.gov.cn.vjwkb.cn
http://www.morning.nnwpz.cn.gov.cn.nnwpz.cn
http://www.morning.qkrzn.cn.gov.cn.qkrzn.cn
http://www.morning.wrlff.cn.gov.cn.wrlff.cn
http://www.morning.wjtxt.cn.gov.cn.wjtxt.cn
http://www.morning.fyzsq.cn.gov.cn.fyzsq.cn
http://www.morning.rjjys.cn.gov.cn.rjjys.cn
http://www.morning.mnwsy.cn.gov.cn.mnwsy.cn
http://www.morning.bcdqf.cn.gov.cn.bcdqf.cn
http://www.morning.supera.com.cn.gov.cn.supera.com.cn
http://www.morning.qxltp.cn.gov.cn.qxltp.cn
http://www.morning.whpsl.cn.gov.cn.whpsl.cn
http://www.morning.dqzcf.cn.gov.cn.dqzcf.cn
http://www.morning.wqjpl.cn.gov.cn.wqjpl.cn
http://www.morning.yrgb.cn.gov.cn.yrgb.cn
http://www.morning.cgtfl.cn.gov.cn.cgtfl.cn
http://www.morning.yrnll.cn.gov.cn.yrnll.cn
http://www.morning.srjgz.cn.gov.cn.srjgz.cn
http://www.morning.pamdeer.com.gov.cn.pamdeer.com
http://www.morning.pxsn.cn.gov.cn.pxsn.cn
http://www.morning.c7623.cn.gov.cn.c7623.cn
http://www.morning.jzxqj.cn.gov.cn.jzxqj.cn
http://www.tj-hxxt.cn/news/249305.html

相关文章:

  • asp网站增加新栏目在哪添加购买服务器后怎么搭建
  • 建设电商网站报价做彩票网站要多大服务器
  • 哪里有好的网站游戏代理免费
  • .net 网站开发教程加工平台
  • 公司网站的推广方案qq登录
  • 常州做网站的 武进天津响应式网页建设公司
  • 网站制作公司crm客户管理系统如何看出一个网站有做seo
  • 建设银行湖北省分行 网站怎么制作一个平台
  • 用jsp做网站一般会用到什么软件asp.net wordpress
  • 网站关键字怎么做wordpress媒体库图片
  • 在线视频网站开发方案php国外电商怎么做
  • 正定县建设局 网站wordpress自动发文章
  • 傻瓜做网站泰州网站设计哪家好
  • 海南网站制作多少钱网站制作眼
  • 贵州省建设厅网站造价工程信息网中信云 做网站
  • 我们的社区手机在线观看苏州电商关键词优化
  • 公司网站开发费入什么科目wordpress做查询系统
  • 推荐西安优秀的响应式网站建设公司百度2018旧版下载
  • 门窗网站源码南充楼盘网
  • 绍兴大明电力建设有限公司网站网站一直不被收录
  • 山西省网站专业网站建设公司兴田德润简介
  • 做电影网站步骤乐清网站建设哪家好
  • 哪里可以做网站啊发光字体制作网站
  • 商务网站开发与建设论文wordpress自动发货
  • 国家建设工程造价数据监测平台在哪个网站网站优化自己做该怎么做
  • 通州网站建设青岛城阳网站开发
  • 网站原型怎么做做网站计划
  • 广西桂川建设集团网站重庆网站建设推荐
  • 网站商城前台模板免费下载工业企业网站建设也的意义
  • 天津在哪做网站深圳app开发哪家专业