最近一段时间学了Python语言,重新学了 Java,js,html语言,CSS,linux,一堆测试工具;唉~
在接触接口测试过程中补了很多课,
终于有点领悟接口测试的根本;
偶是个实用派~,那么现实中没有用的东西,基本上我都不会有很大的概念;
下面给的是接口测试的统一大步骤,其实就是让我们对接口测试有一个整体的概念,我们要做或学习接口测试,应该从那些地方着手,也就是告诉你,百度搜索了半天接口测试之后,我还是没有概念,那怎么办呢,那么下面这些步骤就是,你需要把接口测试拆开来了解的步骤;
如第一步,百度之后,要研究什么是resful,怎么个增删改查;
这些步骤都可以拆开来,反复实践,等把这些步骤都拆开来,实践完了,你的接口测试也就通透了,通杀所有接口测试
接口测试:Http类,webservice类 ?其实大同小异
找一个你自己的项目,没人做过接口测试的也可以,这样你可以自己想明白 怎么测,而不是用别人的思想,思想。。。最重要,可是没有思路到有思路的路程并不长,只是你要开始做这个事情,相信我,会很快,你发现自己确实很聪明~~~~~~
声明:我的这些东西之所以能入门,主要归功于乙醇大神的接口测试概念和冯xx朋友的不吝赐教以及网络上的各种散碎思想;
第一步: 先要明白你要测什么? 本质就是增,删,改,查。(学名叫 resful);
第二步:先用网上推荐的工具来感觉一下(比如:postman, 比如:SoapUI)
第三步:get, post, put, delete 大概怎么个用法,比如传参(比如 json串),怎么看结果(这些确实需要你有些技术基础的,比如 端口,返回值,编码类型)
第四步:那么,那么,我们学了语言,那就来用用吧(一定要拿写好的接口例子来看看,要不然,你不知道用这个语言的什么包或什么函数来帮我们获取到URl的数据等...)
第五步:那么我们加入框架吧(Unittest),这样和前面你的老版本,自创的那一版对比一下,会感触~~,然后明白为什么用框架, 实践确实是个有意思的事情;
第六步:把你的那些参数放入数据库,或者excel等等 实现数据驱动;倒腾吧
第七步:优化你的代码,反复反复倒腾 重构,你应该在通往 python高手的路上了
第八步:当然如果你会Java但是并不会用它写接口测试,那么把这些用例变成Java吧
第九步:那么你还能干嘛,还多着呢,思考:你现在这个接口是否只测试了A接口,那么B接口能测试吗? 比如C调用A接口,那么C是一个接口呢? 是吗~~ 你能分辨出来吗,把它弄清楚,如果不是接口,或者它是什么,能测试吗,怎么测试?
第十步:自己做一个假的接口(Moco):最好和你现在的项目结合的,比如开发正在开发的(和开发沟通);自己测试
第十一步:自己写一个接口(可以先按照之前开发开发好的接口,照葫芦画瓢一个,那也要画,必须画,谁叫你是做测试的,知己知彼呀~),先简单,后复杂,主要倒腾清楚原理就行,反正你也不做开发(当然如果你想做开发,那去做开发吧,别在这浪费时间);自己测试
第十二步: 开始倒腾 测试第二个接口,这次你直接从第六步开始就行(代码优美可不是一天炼成的)
如果你倒腾的很细的话,本人认为倒腾三个接口应该很够了,最后一定记得拿你这个知识到市场去卖钱哟;科技是第一生产力~~
其实,其实 有了这个基础 应该倒腾自动化的其他就不难了
?第一版 unittest 框架源码
1 # Lawsuit_interface_unittest.py
2 # coding:utf-8
3
4 import json
5 import unittest
6 from suds.client import Client
7
8
9 class Lawsuit_interface_testing(unittest.TestCase):
10
11 def setUp(self):
12 self.url = "http://.....:8080/sys/webservice/sysNotifyTodoWebService?wsdl"
13 self.client = Client(self.url) #
14
15 def tearDown(self):
16 pass
17
18 def test_getTodo(self):
19
20 notify_TodoGetContext = self.client.factory.create(
21 'notifyTodoGetContext')
22 notify_TodoGetContext.otherCond = ""
23 notify_TodoGetContext.pageNo = 1
24 notify_TodoGetContext.rowSize = 3
25 notify_TodoGetContext.targets = json.dumps(
26 {"LoginName": "xiaoming"})
27 notify_TodoGetContext.type = 1
28 notify_TodoAppResult = self.client.service.getTodo(
29 notify_TodoGetContext)
30 returnState = notify_TodoAppResult.returnState
31 self.assertEqual(returnState, 2)
32
33 def test_sendTodo(self):
34
35 notify_TodoSendContext = self.client.factory.create(
36 'notifyTodoSendContext')
37 notify_TodoSendContext.appName = "Lawsuit"
38 notify_TodoSendContext.createTime = "2015-11-27 15:32:39"
39 notify_TodoSendContext.key = ''
40 notify_TodoSendContext.link = 'http://wwww.baidu.com'
41 notify_TodoSendContext.subject = 'Lawsuit_testing'
42 notify_TodoSendContext.modelId = '123456789'
43 notify_TodoSendContext.modelName = "Lawsuit"
44 notify_TodoSendContext.targets = json.dumps(
45 {"LoginName": "xiaoming"})
46 notify_TodoSendContext.type = 1
47 notify_TodoAppResult = self.client.service.sendTodo(
48 notify_TodoSendContext)
49 returnState = notify_TodoAppResult.returnState
50 self.assertEqual(returnState, 2)
51
52 def test_deleteTodo(self):
53
54 notify_TodoRemoveContext = self.client.factory.create(
55 'notifyTodoRemoveContext')
56 notify_TodoRemoveContext.appName = "Lawsuit"
57 notify_TodoRemoveContext.modelId = '123456789'
58 notify_TodoRemoveContext.key = ''
59 notify_TodoRemoveContext.modelName = "Lawsuit"
60 notify_TodoRemoveContext.optType = 1
61 notify_TodoRemoveContext.targets = json.dumps(
62 {"LoginName": "xiaoming"})
63 notify_TodoAppResult = self.client.service.deleteTodo(
64 notify_TodoRemoveContext)
65 returnState = notify_TodoAppResult.returnState
66 self.assertEqual(returnState, 2)
67
68 def test_setTodoDone(self):
69
70 notify_TodoRemoveContext = self.client.factory.create(
71 'notifyTodoRemoveContext')
72 notify_TodoRemoveContext.appName = "Lawsuit"
73 notify_TodoRemoveContext.modelId = '123456789'
74 notify_TodoRemoveContext.key = ''
75 notify_TodoRemoveContext.modelName = "Lawsuit_testing"
76 notify_TodoRemoveContext.optType = 1
77 notify_TodoRemoveContext.targets = json.dumps(
78 {"LoginName": "xiaoming"})
79 notify_TodoAppResult = self.client.service.setTodoDone(
80 notify_TodoRemoveContext)
81 returnState = notify_TodoAppResult.returnState
82 self.assertEqual(returnState, 2)
83
84
85 if __name__ == '__main__':
86 unittest.main()
?第二版 使用excel 数据驱动
1 # Lawsuit_interface_unittest_excel_v1.1.py
2 # coding:utf-8
3
4 import unittest
5 import json
6 import xlrd
7 from suds.client import Client
8 import time
9 import sys
10
11
12 class Lawsuit_interface_testing(unittest.TestCase):
13
14 def setUp(self):
15 self.url ='http:// xx?wsdl'
16 self.client = Client(self.url)
17 self.xlsfile = r'lawsuit_casedata.xlsx'
18 self.excel_data(self.xlsfile)
19
20 def tearDown(self):
21 pass
22
23 def test_getToDO(self):
24
25 self.Cannot_find_file(self.xlsfile)
26
27 notify_TodoGetContext = self.client.factory.create(
28 'notifyTodoGetContext')
29 notify_TodoGetContext.pageNo = self.pageNo_value
30 notify_TodoGetContext.rowSize = self.rowSize_value
31 # another way to json
32 # notify_TodoGetContext.targets = "{ \"LoginName\": \"xiaoming\" }"
33 notify_TodoGetContext.targets = self.targets_value
34 notify_TodoGetContext.type = self.ptype_value
35
36 notify_TodoAppResult = self.client.service.getTodo(
37 notify_TodoGetContext)
38 returnState = notify_TodoAppResult.returnState
39
40 print returnState
41 self.assertEqual(returnState, 2)
42
43 def test_sendTodo(self):
44 self.Cannot_find_file(self.xlsfile)
45
46 notify_TodoSendContext = self.client.factory.create(
47 'notifyTodoSendContext')
48 notify_TodoSendContext.appName = self.appName_value
49 notify_TodoSendContext.createTime = self.creatime_value
50 # notify_TodoSendContext.key = ''
51 notify_TodoSendContext.link = self.link_value
52 notify_TodoSendContext.subject = self.subject_value
53 notify_TodoSendContext.modelId = self.modelId_value
54 notify_TodoSendContext.modelName = self.modelName_value
55 notify_TodoSendContext.targets = self.targets_value
56 notify_TodoSendContext.type = self.ptype_value
57 notify_TodoAppResult = self.client.service.sendTodo(
58 notify_TodoSendContext)
59 returnState = notify_TodoAppResult.returnState
60 self.assertEqual(returnState, 2)
61
62 def test_deleteTodo(self):
63 self.Cannot_find_file(self.xlsfile)
64
65 notify_TodoRemoveContext = self.client.factory.create(
66 'notifyTodoRemoveContext')
67 notify_TodoRemoveContext.appName = self.appName_value
68 notify_TodoRemoveContext.modelId = self.modelId_value
69 # notify_TodoRemoveContext.key = ''
70 notify_TodoRemoveContext.modelName = self.modelName_value
71 notify_TodoRemoveContext.optType = self.optType_value
72 notify_TodoRemoveContext.targets = self.targets_value
73 notify_TodoAppResult = self.client.service.deleteTodo(
74 notify_TodoRemoveContext)
75 returnState = notify_TodoAppResult.returnState
76 self.assertEqual(returnState, 2)
77
78 def test_setTodoDone(self):
79 self.Cannot_find_file(self.xlsfile)
80
81 notify_TodoRemoveContext = self.client.factory.create(
82 'notifyTodoRemoveContext')
83 notify_TodoRemoveContext.appName = self.appName_value
84 notify_TodoRemoveContext.modelId = self.modelId_value
85 # notify_TodoRemoveContext.key = ''
86 notify_TodoRemoveContext.modelName = self.modelName_value
87 notify_TodoRemoveContext.optType = self.optType_value
88 notify_TodoRemoveContext.targets = self.targets_value
89 notify_TodoAppResult = self.client.service.setTodoDone(
90 notify_TodoRemoveContext)
91 returnState = notify_TodoAppResult.returnState
92 self.assertEqual(returnState, 2)
93
94 def excel_data(self, xlsfile):
95
96 self.Cannot_find_file(self.xlsfile)
97 book = xlrd.open_workbook(xlsfile)
98 api_sheet = book.sheet_by_index(0)
99 nrows = api_sheet.nrows
100 for i in range(1, nrows):
101 caseID = api_sheet.cell(i, 0)
102 appName = api_sheet.cell(i, 1)
103 creatime = time.strftime(
104 time.strftime('%Y-%m-%d %X', time.localtime(time.time())))
105 link = api_sheet.cell(i, 3)
106 subject = api_sheet.cell(i, 4)
107 modelId = api_sheet.cell(i, 5)
108 modelName = api_sheet.cell(i, 6)
109 targets = api_sheet.cell(i, 7)
110 ptype = api_sheet.cell(i, 8)
111 pageNo = api_sheet.cell(i, 9)
112 rowSize = api_sheet.cell(i, 10)
113 optType = api_sheet.cell(i, 11)
114 # returnstatue = api_sheet.cell(i, 12)
115 # message = api_sheet.cell(i, 13)
116 if api_sheet.cell(i, 0).ctype != 0:
117 # caseID_value=str(int(caseID.value))
118 self.appName_value = appName.value
119 self.creatime_value=creatime
120 self.link_value = link.value
121 self.subject_value = subject.value
122 self.modelId_value = modelId.value
123 self.modelName_value = modelName.value
124 # print type(targets)
125 self.targets_value = targets.value
126 # print type(targets.value)
127 self.ptype_value = int(ptype.value)
128 self.pageNo_value = int(pageNo.value)
129 self.rowSize_value = int(rowSize.value)
130 self.optType_value = int(optType.value)
131
132 # returnstatue_value=returnstatue.value
133 # message_value=message.value
134 else:
135 return 0
136 # data1=
137
138 # return data1
139
140 # exception
141
142 def Cannot_find_file(self, xlsfile):
143 try:
144 foo = open(self.xlsfile)
145 except EnvironmentError as err:
146 print "Unable to open file:{}".format(err)
147 sys.exit(1)
148
149
150 if __name__ == '__main__':
151 unittest.main()
感谢每一个认真阅读我文章的人!!!
作为一位过来人也是希望大家少走一些弯路,如果你不想再体验一次学习时找不到资料,没人解答问题,坚持几天便放弃的感受的话,在这里我给大家分享一些自动化测试的学习资源,希望能给你前进的路上带来帮助
??视频文档获取方式:
这份文档和视频资料,对于想从事【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴我走过了最艰难的路程,希望也能帮助到你!以上均可以分享,点下方小卡片即可自行领取