zoukankan      html  css  js  c++  java
  • python-ddt 数据驱动测试

     1 # @File : learn_ddt.py
     2 
     3 #-*- coding:utf-8 -*-
     4 
     5 #本次学习:ddt  ---data drive test--数据驱动测试
     6 #1.安装 pip install ddt
     7 #2.用途:结合单元测试去执行用例
     8 #3.本质:类的装饰器
     9 
    10 # def print_msg(*args):#动态参数
    11 #     print(args)#*args 到了函数内部之后就变成一个元祖
    12 #     print('参数的长度:',len(args))
    13 #
    14 # a=(1,2,3)
    15 # print_msg(*a)#拆分一层
    16 #
    17 # b=[(1,2),3,[4,5]]
    18 # print_msg(*b)
    19 
    20 import unittest
    21 from ddt import ddt,data,unpack
    22 
    23 test_data=[{'param':{'mobilephone':18688773467,'pwd':'123456'},'http_method':'get','excepted':'登录成功',
    24             'url':'http://47.107.168.87:8080/futureloan/mvc/api/member/login'},
    25 
    26            {'param':{'mobilephone':18688773467,'pwd':'1234567'},'http_method':'post','excepted':'用户名或密码错误',
    27             'url':'http://47.107.168.87:8080/futureloan/mvc/api/member/login'},
    28 
    29             {'param':{'mobilephone':18688773467,'amount':'1000'},'http_method':'post','excepted':'充值成功',
    30              'url':'http://47.107.168.87:8080/futureloan/mvc/api/member/recharge'}]
    31 
    32 @ddt #装饰类
    33 class TestMath(unittest.TestCase):
    34 
    35     @data(test_data) #@data装饰方法
    36     def test_001(self,item):
    37         print('-----------用例1-----------')
    38         print('item:',item)
    39 
    40     @data(*test_data) #@data装饰方法,  加上* 拆分一层(按逗号拆分)
    41     def test_002(self,item):
    42         print('-----------用例2-----------')
    43         print('item:',item)
    44 
    45     @data(*test_data)
    46     @unpack#在@data拆分的基础上,再拆分一次,并用等量的变量接收这些数据(如果是字典,需要用key)
    47     def test_002(self,param,http_method,excepted,url):
    48         print('-----------用例3-----------')
    49         print('param:',param)
    50         print('http_method:',http_method)
    51         print('excepted:',excepted)
    52         print('url:',url)
    53 
    54 if __name__ == '__main__':
    55     unittest.main()
  • 相关阅读:
    ueditor精简插件和减少初次加载文件的方法
    The Art of Mocking
    What is a mocking framework? Why is it useful?
    黑盒测试、白盒测试、单元测试、集成测试、系统测试、验收测试的区别与联系
    What is the purpose of mock objects?
    What is Mocking?
    APPENDIX: How to apply the Apache License to your work
    开源 ≠ 免费,开源协议License详解
    如何选择开源许可证?
    五种开源协议的比较(BSD,Apache,GPL,LGPL,MIT) – 整理
  • 原文地址:https://www.cnblogs.com/Aphrodite/p/10093616.html
Copyright © 2011-2022 走看看