zoukankan      html  css  js  c++  java
  • UnitTest基本用法

     /Python中相对流行的自动化测试框架UnitTest(PyUnit),在Java中有Junit测试框架。
    4个特点:
    1.TestCase:测试用例,所有的用例都是直接继承于UnitTest.TestCase类.
    2.TestFixture:SetUp和Teardown,作为前置条件和后置条件.
    3.TestSuite:测试套件
    4.TestRunner:测试运行器
    5.断言:UnitTest中封装好了断言,可以直接调用
    UnitTest环境搭建:
    Python安装时已经默认封装好了UintTest框架调用框架只需要import。
    UnitTest语法规则:
    1.UnitTest中,测试用例定义都是以test开头
    2.用例排序是按照0-9,A-Z,a-z
    数据驱动:
    分割数据和代码块
    在UnitTest 通过DDT -data driver test 实现
    一个参数用@data
    eg:@ddt
    @data("666666")
        def test_2(self, username):
            self.driver.find_element_by_name("accounts").send_keys(username)
            self.driver.find_element_by_name("123456").send_keys(password)
    如果是多个参数,
    from ddt import ddt,data,unpack
    @data(['666666', '123456'],['123456', '123456'])
        @unpack
        def test_2(self, username,password):
            self.driver.find_element_by_name("accounts").send_keys(username)
            self.driver.find_element_by_name("pwd").send_keys(password)
    如果是更多的参数,如上方法就不适用,需要读取文件
    @data(* read_file())
    *表示元组形式解析
    **表示字典形式解析
    DDT可以直接读取yaml文件
    cmd-》pip install pyyaml
    pycharm ->setting->导入yaml-》install package
    test.yaml如下
    username:666666
    password:123456
    eg:
    #传入参数是字典形式,file_data用
    from ddt import ddt,data,unpack,file_data
    @file_data('test.yaml')
    def test_1(self,**user):
    name=user.get('name')
    pwd=user.get('pwd')
    print(user)
    传入的参数是字典格式,不用@unpack进行数据解包
    @uinttest.skip() #无条件跳过本次执行用例
    @uinttest.skipUnless(1>2,'这是Unless理由')
    @uinttest.skipif(1>2,'这是if理由')
     
  • 相关阅读:
    iot 表索引dump《2》
    heap表和iot表排序规则不同
    Cannot complete the install because one or more required items could not be found.
    iot表输出按主键列排序,heap表不是
    iot 表主键存放所有数据,且按数据插入顺序排序
    iot表和heap表排序规则不同
    org.eclipse.graphiti.ui.editor.DiagramEditorInput.
    Oracle 排序规则
    perl 异步超时 打印错误
    14.6.3 Grouping DML Operations with Transactions 组DML操作
  • 原文地址:https://www.cnblogs.com/JacquelineQA/p/12666889.html
Copyright © 2011-2022 走看看