首页 > 其他 > 详细

unittest参数化

时间:2019-06-12 22:13:06      阅读:132      评论:0      收藏:0      [点我收藏+]
import requests
import unittest
from parameterized import parameterized as pd


def read_file(file_name):
    result = []
    with open(file_name, encoding=‘utf-8‘) as fr:
        for line in fr:
            line = line.strip()
            if line:
                result.append(line.split(‘,‘))
    return result


def read_excel():
    pass


def get_data_from_mysql(sql):
    pass


class InterFaceCase(unittest.TestCase):

    @pd.expand([
        [‘http://api.nnzhp.cn/api/user/stu_info‘, ‘stu_name=矿泉水‘, ‘矿泉水‘],
        [‘http://api.nnzhp.cn/api/user/stu_info‘, ‘stu_name=小黑‘, ‘小黑‘],
        [‘http://api.nnzhp.cn/api/user/stu_info‘, ‘stu_name=‘, ‘小黑‘],
    ])
    #@pd.expand(read_file(‘login.txt‘))
    def testlogin(self, url, data, check):
        # username=abc&password=1234
        url = url + ‘?‘ + data
        result = requests.get(url).text
     #判断check是否包含在result中

self.assertIn(check, result) # 1、查找测试用例 unittest.main()

 

unittest参数化

原文:https://www.cnblogs.com/skyxiuli/p/11012840.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!