• 接口测试练习步骤


    在接触接口测试过程中补了很多课,

    终于有点领悟接口测试的根本;

    偶是个实用派~,那么现实中没有用的东西,基本上我都不会有很大的概念;

    下面给的是接口测试的统一大步骤,其实就是让我们对接口测试有一个整体的概念,我们要做或学习接口测试,应该从那些地方着手,也就是告诉你,百度搜索了半天接口测试之后,我还是没有概念,那怎么办呢,那么下面这些步骤就是,你需要把接口测试拆开来了解的步骤;

    如第一步,百度之后,要研究什么是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. 1 # Lawsuit_interface_unittest.py
    2. 2 # coding:utf-8
    3. 3
    4. 4 import json
    5. 5 import unittest
    6. 6 from suds.client import Client
    7. 7
    8. 8
    9. 9 class Lawsuit_interface_testing(unittest.TestCase):
    10. 10
    11. 11 def setUp(self):
    12. 12 self.url = "http://.....:8080/sys/webservice/sysNotifyTodoWebService?wsdl"
    13. 13 self.client = Client(self.url) #
    14. 14
    15. 15 def tearDown(self):
    16. 16 pass
    17. 17
    18. 18 def test_getTodo(self):
    19. 19
    20. 20 notify_TodoGetContext = self.client.factory.create(
    21. 21 'notifyTodoGetContext')
    22. 22 notify_TodoGetContext.otherCond = ""
    23. 23 notify_TodoGetContext.pageNo = 1
    24. 24 notify_TodoGetContext.rowSize = 3
    25. 25 notify_TodoGetContext.targets = json.dumps(
    26. 26 {"LoginName": "xiaoming"})
    27. 27 notify_TodoGetContext.type = 1
    28. 28 notify_TodoAppResult = self.client.service.getTodo(
    29. 29 notify_TodoGetContext)
    30. 30 returnState = notify_TodoAppResult.returnState
    31. 31 self.assertEqual(returnState, 2)
    32. 32
    33. 33 def test_sendTodo(self):
    34. 34
    35. 35 notify_TodoSendContext = self.client.factory.create(
    36. 36 'notifyTodoSendContext')
    37. 37 notify_TodoSendContext.appName = "Lawsuit"
    38. 38 notify_TodoSendContext.createTime = "2015-11-27 15:32:39"
    39. 39 notify_TodoSendContext.key = ''
    40. 40 notify_TodoSendContext.link = 'http://wwww.baidu.com'
    41. 41 notify_TodoSendContext.subject = 'Lawsuit_testing'
    42. 42 notify_TodoSendContext.modelId = '123456789'
    43. 43 notify_TodoSendContext.modelName = "Lawsuit"
    44. 44 notify_TodoSendContext.targets = json.dumps(
    45. 45 {"LoginName": "xiaoming"})
    46. 46 notify_TodoSendContext.type = 1
    47. 47 notify_TodoAppResult = self.client.service.sendTodo(
    48. 48 notify_TodoSendContext)
    49. 49 returnState = notify_TodoAppResult.returnState
    50. 50 self.assertEqual(returnState, 2)
    51. 51
    52. 52 def test_deleteTodo(self):
    53. 53
    54. 54 notify_TodoRemoveContext = self.client.factory.create(
    55. 55 'notifyTodoRemoveContext')
    56. 56 notify_TodoRemoveContext.appName = "Lawsuit"
    57. 57 notify_TodoRemoveContext.modelId = '123456789'
    58. 58 notify_TodoRemoveContext.key = ''
    59. 59 notify_TodoRemoveContext.modelName = "Lawsuit"
    60. 60 notify_TodoRemoveContext.optType = 1
    61. 61 notify_TodoRemoveContext.targets = json.dumps(
    62. 62 {"LoginName": "xiaoming"})
    63. 63 notify_TodoAppResult = self.client.service.deleteTodo(
    64. 64 notify_TodoRemoveContext)
    65. 65 returnState = notify_TodoAppResult.returnState
    66. 66 self.assertEqual(returnState, 2)
    67. 67
    68. 68 def test_setTodoDone(self):
    69. 69
    70. 70 notify_TodoRemoveContext = self.client.factory.create(
    71. 71 'notifyTodoRemoveContext')
    72. 72 notify_TodoRemoveContext.appName = "Lawsuit"
    73. 73 notify_TodoRemoveContext.modelId = '123456789'
    74. 74 notify_TodoRemoveContext.key = ''
    75. 75 notify_TodoRemoveContext.modelName = "Lawsuit_testing"
    76. 76 notify_TodoRemoveContext.optType = 1
    77. 77 notify_TodoRemoveContext.targets = json.dumps(
    78. 78 {"LoginName": "xiaoming"})
    79. 79 notify_TodoAppResult = self.client.service.setTodoDone(
    80. 80 notify_TodoRemoveContext)
    81. 81 returnState = notify_TodoAppResult.returnState
    82. 82 self.assertEqual(returnState, 2)
    83. 83
    84. 84
    85. 85 if __name__ == '__main__':
    86. 86 unittest.main()

     第二版 使用excel 数据驱动

    1. 1 # Lawsuit_interface_unittest_excel_v1.1.py
    2. 2 # coding:utf-8
    3. 3
    4. 4 import unittest
    5. 5 import json
    6. 6 import xlrd
    7. 7 from suds.client import Client
    8. 8 import time
    9. 9 import sys
    10. 10
    11. 11
    12. 12 class Lawsuit_interface_testing(unittest.TestCase):
    13. 13
    14. 14 def setUp(self):
    15. 15 self.url ='http:// xx?wsdl'
    16. 16 self.client = Client(self.url)
    17. 17 self.xlsfile = r'lawsuit_casedata.xlsx'
    18. 18 self.excel_data(self.xlsfile)
    19. 19
    20. 20 def tearDown(self):
    21. 21 pass
    22. 22
    23. 23 def test_getToDO(self):
    24. 24
    25. 25 self.Cannot_find_file(self.xlsfile)
    26. 26
    27. 27 notify_TodoGetContext = self.client.factory.create(
    28. 28 'notifyTodoGetContext')
    29. 29 notify_TodoGetContext.pageNo = self.pageNo_value
    30. 30 notify_TodoGetContext.rowSize = self.rowSize_value
    31. 31 # another way to json
    32. 32 # notify_TodoGetContext.targets = "{ \"LoginName\": \"xiaoming\" }"
    33. 33 notify_TodoGetContext.targets = self.targets_value
    34. 34 notify_TodoGetContext.type = self.ptype_value
    35. 35
    36. 36 notify_TodoAppResult = self.client.service.getTodo(
    37. 37 notify_TodoGetContext)
    38. 38 returnState = notify_TodoAppResult.returnState
    39. 39
    40. 40 print returnState
    41. 41 self.assertEqual(returnState, 2)
    42. 42
    43. 43 def test_sendTodo(self):
    44. 44 self.Cannot_find_file(self.xlsfile)
    45. 45
    46. 46 notify_TodoSendContext = self.client.factory.create(
    47. 47 'notifyTodoSendContext')
    48. 48 notify_TodoSendContext.appName = self.appName_value
    49. 49 notify_TodoSendContext.createTime = self.creatime_value
    50. 50 # notify_TodoSendContext.key = ''
    51. 51 notify_TodoSendContext.link = self.link_value
    52. 52 notify_TodoSendContext.subject = self.subject_value
    53. 53 notify_TodoSendContext.modelId = self.modelId_value
    54. 54 notify_TodoSendContext.modelName = self.modelName_value
    55. 55 notify_TodoSendContext.targets = self.targets_value
    56. 56 notify_TodoSendContext.type = self.ptype_value
    57. 57 notify_TodoAppResult = self.client.service.sendTodo(
    58. 58 notify_TodoSendContext)
    59. 59 returnState = notify_TodoAppResult.returnState
    60. 60 self.assertEqual(returnState, 2)
    61. 61
    62. 62 def test_deleteTodo(self):
    63. 63 self.Cannot_find_file(self.xlsfile)
    64. 64
    65. 65 notify_TodoRemoveContext = self.client.factory.create(
    66. 66 'notifyTodoRemoveContext')
    67. 67 notify_TodoRemoveContext.appName = self.appName_value
    68. 68 notify_TodoRemoveContext.modelId = self.modelId_value
    69. 69 # notify_TodoRemoveContext.key = ''
    70. 70 notify_TodoRemoveContext.modelName = self.modelName_value
    71. 71 notify_TodoRemoveContext.optType = self.optType_value
    72. 72 notify_TodoRemoveContext.targets = self.targets_value
    73. 73 notify_TodoAppResult = self.client.service.deleteTodo(
    74. 74 notify_TodoRemoveContext)
    75. 75 returnState = notify_TodoAppResult.returnState
    76. 76 self.assertEqual(returnState, 2)
    77. 77
    78. 78 def test_setTodoDone(self):
    79. 79 self.Cannot_find_file(self.xlsfile)
    80. 80
    81. 81 notify_TodoRemoveContext = self.client.factory.create(
    82. 82 'notifyTodoRemoveContext')
    83. 83 notify_TodoRemoveContext.appName = self.appName_value
    84. 84 notify_TodoRemoveContext.modelId = self.modelId_value
    85. 85 # notify_TodoRemoveContext.key = ''
    86. 86 notify_TodoRemoveContext.modelName = self.modelName_value
    87. 87 notify_TodoRemoveContext.optType = self.optType_value
    88. 88 notify_TodoRemoveContext.targets = self.targets_value
    89. 89 notify_TodoAppResult = self.client.service.setTodoDone(
    90. 90 notify_TodoRemoveContext)
    91. 91 returnState = notify_TodoAppResult.returnState
    92. 92 self.assertEqual(returnState, 2)
    93. 93
    94. 94 def excel_data(self, xlsfile):
    95. 95
    96. 96 self.Cannot_find_file(self.xlsfile)
    97. 97 book = xlrd.open_workbook(xlsfile)
    98. 98 api_sheet = book.sheet_by_index(0)
    99. 99 nrows = api_sheet.nrows
    100. 100 for i in range(1, nrows):
    101. 101 caseID = api_sheet.cell(i, 0)
    102. 102 appName = api_sheet.cell(i, 1)
    103. 103 creatime = time.strftime(
    104. 104 time.strftime('%Y-%m-%d %X', time.localtime(time.time())))
    105. 105 link = api_sheet.cell(i, 3)
    106. 106 subject = api_sheet.cell(i, 4)
    107. 107 modelId = api_sheet.cell(i, 5)
    108. 108 modelName = api_sheet.cell(i, 6)
    109. 109 targets = api_sheet.cell(i, 7)
    110. 110 ptype = api_sheet.cell(i, 8)
    111. 111 pageNo = api_sheet.cell(i, 9)
    112. 112 rowSize = api_sheet.cell(i, 10)
    113. 113 optType = api_sheet.cell(i, 11)
    114. 114 # returnstatue = api_sheet.cell(i, 12)
    115. 115 # message = api_sheet.cell(i, 13)
    116. 116 if api_sheet.cell(i, 0).ctype != 0:
    117. 117 # caseID_value=str(int(caseID.value))
    118. 118 self.appName_value = appName.value
    119. 119 self.creatime_value=creatime
    120. 120 self.link_value = link.value
    121. 121 self.subject_value = subject.value
    122. 122 self.modelId_value = modelId.value
    123. 123 self.modelName_value = modelName.value
    124. 124 # print type(targets)
    125. 125 self.targets_value = targets.value
    126. 126 # print type(targets.value)
    127. 127 self.ptype_value = int(ptype.value)
    128. 128 self.pageNo_value = int(pageNo.value)
    129. 129 self.rowSize_value = int(rowSize.value)
    130. 130 self.optType_value = int(optType.value)
    131. 131
    132. 132 # returnstatue_value=returnstatue.value
    133. 133 # message_value=message.value
    134. 134 else:
    135. 135 return 0
    136. 136 # data1=
    137. 137
    138. 138 # return data1
    139. 139
    140. 140 # exception
    141. 141
    142. 142 def Cannot_find_file(self, xlsfile):
    143. 143 try:
    144. 144 foo = open(self.xlsfile)
    145. 145 except EnvironmentError as err:
    146. 146 print "Unable to open file:{}".format(err)
    147. 147 sys.exit(1)
    148. 148
    149. 149
    150. 150 if __name__ == '__main__':
    151. 151 unittest.main()

    2023最新Jmeter接口测试从入门到精通(全套项目实战教程)

  • 相关阅读:
    聚类算法的先验基础知识
    Kubernetes的原理及应用详解(一)
    Java进阶03 IO基础
    获取店铺所有商品API 返回值说明
    基于51单片机pwm调光护眼台灯智能检测光强光控灯设计proteus仿真原理图PCB
    list分组成map这样做更简单
    CSS 边框
    Django 实现连续请求
    二叉(搜索)树的最近公共祖先 ●●
    最长递增子序列及最优解、动物总重量问题
  • 原文地址:https://blog.csdn.net/dq565/article/details/133241918