class TestMethod(unittest.TestCase): def setUp(self): self.run = RunMain() print('这个是开始执行的方法') def tearDown(self): print('这个是执行之后的方法') def test_01(self): url2 = 'http://192.168.10.166:9006/rest/sxreader/getAllTeacherTaskInfos?activity=0&condition=&indexPage=1&pageSize=12&status=unfinished&userId=60da42581d4b11eaa0046c92bf28f871' res_data = dict(userid=111, extno="") res = self.run.run_main(url2, 'GET', res_data) self.assertEqual(res['code'], 200, msg='测试通过') print(res) def test_02(self): url = 'http://192.168.10.166:9006/login' data = {'username': '******', 'password': '******'} res2 = self.run.run_main(url, 'POST', data) self.assertEqual(res2['userName'], '232323', msg='测试通过') print(res2) print('这个是测试用例2')
class TestMethod(unittest.TestCase): def setUp(self): self.run = RunMain() def test_01(self): url = 'https://h5app-dev.multilotto.net/api/user/getcountryidbyip' data = { "language": "EN", "platform": "3000", "remote_addr": "13.230.65.62", "userid": "", "subchannel": "10004", "casinoversion": "2.7.0", "version": "2.7.0", "pushid": "a7b69ace-4b6d-49e4-8ef4-077 c58a182b2 ", "usercheck ": "", "username ": "", "pushproject ": "curacao ", "uniq ": "D69DE874-EA21-40A7-8DA3-8FDE0BC5DE61", } # mock模拟这个返回值 print('----------------------') mock_data = mock.Mock(return_value=data) # print(mock_data) print('----------------------') self.run.runmain = mock_data res = self.run.runmain(url, 'POST', data) print(res) # print('----------------') # print(type(res)) # # print(res['CODE']) # print('----------------') self.assertEqual(res['CODE'], '1', "测试失败") # 设置全局变量 # globals()['userid']='100099' print('这是第一个case')
class TestMethod(unittest.TestCase): def setUp(self): self.run = RunMain() # 这种方法虽然可以,但如果参数较多,则不可行;且case间是相互独立的,不应该这么操作 # self.userid =self.test_01( def test_01(self): url = 'https://h5app-dev.multilotto.net/api/user/getcountryidbyip' data ={ "language": "EN", "platform": "3000", "remote_addr": "13.230.65.62", "userid": "", "subchannel": "10004", "casinoversion": "2.7.0", "version": "2.7.0", "pushid": "a7b69ace-4b6d-49e4-8ef4-077 c58a182b2 ", "usercheck ": "", "username ": "", "pushproject ": "curacao ", "uniq ": "D69DE874-EA21-40A7-8DA3-8FDE0BC5DE61", } # self.userid=10002 # run = RunMain() # res = self.setUp() 当前问题,只能这样调用,不能传参? # 要在setup中也加self res = self.run.runmain(url,'POST',data) print(res) print('----------------') print(type(res)) # print(res['CODE']) print('----------------') self.assertEqual(res['CODE'],'1',"测试失败") # 设置全局变量 # globals()['userid']='100099' #TO DO # 这个报错我暂不知 # print(userid) print('这是第一个case') # 跳过执行某个用例 # @unittest.skip('test_02') # 返回到setup中,给其他用例用--但不推荐 # return self.userid # self.assertNotEqual() # self.assertTrue() # # if res['CODE'] == '1': # print('testcase1 测试通过') # else: # print('testcase1 测试失败') # unitest中,会按字母顺序来执行的,所以要注意执行顺序 def test_02(self): # 使用别的用例返回的数据,但不推荐 # print(self.userid) # print(userid) url = 'http://www.imooc.com/m/web/shizhanapi/loadmorepingjia.html' data = { 'cart':'11' } res = self.run.runmain(url,'GET') # print(res) self.assertEqual(res['data']['errorCode'],1006,"测试失败") print("这是第二个case")
def setUp(self): self.run = RunMain()
def setUp(self): self.run = RunMain() print('这个是开始执行的方法')