在testcase目录下,创建loginTest.py文件,case文件命名规则:*Test.py #coding=utf-8 ''' Created on 2019-2-1 author: codeali ''' import requests import unittest import logging from lib import log from lib.headers import appheaders from lib import config from lib.dataparse import getDataFromXml global URL URLLIST = { 'login_url': config.loginurl() } global DATAS DATAS = getDataFromXml("userapi.xml", "login") class LoginTest(unittest.TestCase): def setUp(self): print('用例描述:用户登录接口测试:\n') '''用例方法命名规则:test + 摘要 + 编号''' def test_login_1001(self): '''用户登录''' expectres = DATAS['expectres'] testdata = { 'username' : DATAS['username'], 'password' : DATAS['password'] } try: login_res = requests.post(URLLIST["login_url"], testdata, appheaders()).json() print(login_res) if (login_res['result']['msg'] == expectres): res = True else: res = False except: res = False self.assertEqual(res, True) def tearDown(self): print('用例执行结束') if __name__ == "__main__": test = LoginTest() test.test_login_1001()
下一步将case文件中的方法添加到suite中,使用HTMLTestRunner生成测试报告。