接口测试的一般步骤

  1. 先有对应的测试文档。
  2. 根据文档上的定义
    1. 请求地址 URL
    2. 请求方式 GET,POST。。。。
    3. 请求参数:
    4. 服务器响应结果(预期结果)
  3. 使用工具Postman 将这些内容输入进去,查看服务器返回的结果是否正确

用户认证问题

在一些商业应用中,API调用都需要用到用户的信息认证,
常用的认证方式

  1. token 令牌的方式
  2. appcode app密钥认证

postman 发送get请求

前提条件

AppCode:36a6d64593884af1971d218d14a23f9d

天气预报接口

官方地址:https://market.aliyun.com/products/57126001/cmapi014302.html?spm=5176.2020520132.101.2.6fbf7218dZwHbG#sku=yuncode830200000


查询天气信息

接口地址: http://jisutqybmf.market.alicloudapi.com/weather/query
请求方式: GET
请求参数(Headers):

Authorization APPCODE 36a6d64593884af1971d218d14a23f9d

请求参数(Query):

名称 类型 是否必须 描述
city STRING 可选 城市(city,cityid,citycode三者任选其一)
citycode STRING 可选 城市天气代号(city,cityid,citycode三者任选其一)
cityid STRING 可选 城市ID(city,cityid,citycode三者任选其一)
ip STRING 可选 IP
location STRING 可选 经纬度 纬度在前,,分割 如:39.983424,116.322987

请求参数(Body): 无

返回结果:

  1. {
  2. "status": 0,
  3. "msg": "ok",
  4. "result": {
  5. "city": "上海",
  6. "cityid": 24,
  7. "citycode": 101020100,
  8. "date": "2021-09-28",
  9. "week": "星期二",
  10. "weather": "多云",
  11. "temp": "29",
  12. "temphigh": "32",
  13. "templow": "24",
  14. "img": "1",
  15. "humidity": "64",
  16. "pressure": "1012",
  17. "windspeed": "1.8",
  18. "winddirect": "西北风",
  19. "windpower": "2级",
  20. "updatetime": "2021-09-28 10:19:00",
  21. "index": [
  22. {
  23. "iname": "空调指数",
  24. "ivalue": "部分时间开启",
  25. "detail": "天气热,到中午的时候您将会感到有点热,因此建议在午后较热时开启制冷空调。"
  26. },
  27. {
  28. "iname": "运动指数",
  29. "ivalue": "较适宜",
  30. "detail": "天气较好,但因气温较高且风力较强,请适当降低运动强度并注意户外防风。推荐您进行室内运动。"
  31. },
  32. {
  33. "iname": "紫外线指数",
  34. "ivalue": "中等",
  35. "detail": "属中等强度紫外线辐射天气,外出时建议涂擦SPF高于15、PA+的防晒护肤品,戴帽子、太阳镜。"
  36. },
  37. {
  38. "iname": "感冒指数",
  39. "ivalue": "少发",
  40. "detail": "各项气象条件适宜,发生感冒机率较低。但请避免长期处于空调房间中,以防感冒。"
  41. },
  42. {
  43. "iname": "洗车指数",
  44. "ivalue": "较适宜",
  45. "detail": "较适宜洗车,未来一天无雨,风力较小,擦洗一新的汽车至少能保持一天。"
  46. },
  47. {
  48. "iname": "空气污染扩散指数",
  49. "ivalue": "良",
  50. "detail": "气象条件有利于空气污染物稀释、扩散和清除,可在室外正常活动。"
  51. },
  52. {
  53. "iname": "穿衣指数",
  54. "ivalue": "炎热",
  55. "detail": "天气炎热,建议着短衫、短裙、短裤、薄型T恤衫等清凉夏季服装。"
  56. }
  57. ],
  58. "aqi": {
  59. "so2": "8",
  60. "so224": "0",
  61. "no2": "33",
  62. "no224": "0",
  63. "co": "0.710",
  64. "co24": "0.000",
  65. "o3": "67",
  66. "o38": "0",
  67. "o324": "0",
  68. "pm10": "47",
  69. "pm1024": "0",
  70. "pm2_5": "31",
  71. "pm2_524": "0",
  72. "iso2": "3",
  73. "ino2": "17",
  74. "ico": "8",
  75. "io3": "22",
  76. "io38": "0",
  77. "ipm10": "46",
  78. "ipm2_5": "44",
  79. "aqi": "46",
  80. "primarypollutant": "PM10",
  81. "quality": "优",
  82. "timepoint": "2021-09-28 09:00:00",
  83. "aqiinfo": {
  84. "level": "一级",
  85. "color": "#00e400",
  86. "affect": "空气质量令人满意,基本无空气污染",
  87. "measure": "各类人群可正常活动"
  88. }
  89. },
  90. "daily": [
  91. {
  92. "date": "2021-09-28",
  93. "week": "星期二",
  94. "sunrise": "05:45",
  95. "sunset": "17:44",
  96. "night": {
  97. "weather": "晴",
  98. "templow": "24",
  99. "img": "0",
  100. "winddirect": "南风",
  101. "windpower": "微风"
  102. },
  103. "day": {
  104. "weather": "多云",
  105. "temphigh": "32",
  106. "img": "1",
  107. "winddirect": "东南风",
  108. "windpower": "微风"
  109. }
  110. },
  111. {
  112. "date": "2021-09-29",
  113. "week": "星期三",
  114. "sunrise": "05:45",
  115. "sunset": "17:43",
  116. "night": {
  117. "weather": "阴",
  118. "templow": "24",
  119. "img": "2",
  120. "winddirect": "西北风",
  121. "windpower": "微风"
  122. },
  123. "day": {
  124. "weather": "多云",
  125. "temphigh": "32",
  126. "img": "1",
  127. "winddirect": "南风",
  128. "windpower": "微风"
  129. }
  130. },
  131. {
  132. "date": "2021-09-30",
  133. "week": "星期四",
  134. "sunrise": "05:46",
  135. "sunset": "17:42",
  136. "night": {
  137. "weather": "多云",
  138. "templow": "21",
  139. "img": "1",
  140. "winddirect": "北风",
  141. "windpower": "微风"
  142. },
  143. "day": {
  144. "weather": "晴",
  145. "temphigh": "29",
  146. "img": "0",
  147. "winddirect": "北风",
  148. "windpower": "微风"
  149. }
  150. },
  151. {
  152. "date": "2021-10-01",
  153. "week": "星期五",
  154. "sunrise": "05:47",
  155. "sunset": "17:40",
  156. "night": {
  157. "weather": "晴",
  158. "templow": "22",
  159. "img": "0",
  160. "winddirect": "东南风",
  161. "windpower": "微风"
  162. },
  163. "day": {
  164. "weather": "晴",
  165. "temphigh": "30",
  166. "img": "0",
  167. "winddirect": "东风",
  168. "windpower": "微风"
  169. }
  170. },
  171. {
  172. "date": "2021-10-02",
  173. "week": "星期六",
  174. "sunrise": "05:47",
  175. "sunset": "17:39",
  176. "night": {
  177. "weather": "晴",
  178. "templow": "23",
  179. "img": "0",
  180. "winddirect": "东南风",
  181. "windpower": "微风"
  182. },
  183. "day": {
  184. "weather": "晴",
  185. "temphigh": "30",
  186. "img": "0",
  187. "winddirect": "东南风",
  188. "windpower": "微风"
  189. }
  190. },
  191. {
  192. "date": "2021-10-03",
  193. "week": "星期日",
  194. "sunrise": "05:48",
  195. "sunset": "17:38",
  196. "night": {
  197. "weather": "晴",
  198. "templow": "24",
  199. "img": "0",
  200. "winddirect": "南风",
  201. "windpower": "微风"
  202. },
  203. "day": {
  204. "weather": "多云",
  205. "temphigh": "30",
  206. "img": "1",
  207. "winddirect": "东南风",
  208. "windpower": "微风"
  209. }
  210. },
  211. {
  212. "date": "2021-10-04",
  213. "week": "星期一",
  214. "sunrise": "05:48",
  215. "sunset": "17:37",
  216. "night": {
  217. "weather": "晴",
  218. "templow": "25",
  219. "img": "0",
  220. "winddirect": "东南风",
  221. "windpower": "微风"
  222. },
  223. "day": {
  224. "weather": "多云",
  225. "temphigh": "30",
  226. "img": "1",
  227. "winddirect": "东南风",
  228. "windpower": "微风"
  229. }
  230. }
  231. ],
  232. "hourly": [
  233. {
  234. "time": "10:00",
  235. "weather": "多云",
  236. "temp": "28",
  237. "img": "1"
  238. },
  239. {
  240. "time": "11:00",
  241. "weather": "多云",
  242. "temp": "29",
  243. "img": "1"
  244. },
  245. {
  246. "time": "12:00",
  247. "weather": "多云",
  248. "temp": "30",
  249. "img": "1"
  250. },
  251. {
  252. "time": "13:00",
  253. "weather": "多云",
  254. "temp": "31",
  255. "img": "1"
  256. },
  257. {
  258. "time": "14:00",
  259. "weather": "多云",
  260. "temp": "32",
  261. "img": "1"
  262. },
  263. {
  264. "time": "15:00",
  265. "weather": "多云",
  266. "temp": "32",
  267. "img": "1"
  268. },
  269. {
  270. "time": "16:00",
  271. "weather": "多云",
  272. "temp": "31",
  273. "img": "1"
  274. },
  275. {
  276. "time": "17:00",
  277. "weather": "多云",
  278. "temp": "31",
  279. "img": "1"
  280. },
  281. {
  282. "time": "18:00",
  283. "weather": "晴",
  284. "temp": "30",
  285. "img": "0"
  286. },
  287. {
  288. "time": "19:00",
  289. "weather": "晴",
  290. "temp": "29",
  291. "img": "0"
  292. },
  293. {
  294. "time": "20:00",
  295. "weather": "晴",
  296. "temp": "28",
  297. "img": "0"
  298. },
  299. {
  300. "time": "21:00",
  301. "weather": "晴",
  302. "temp": "27",
  303. "img": "0"
  304. },
  305. {
  306. "time": "22:00",
  307. "weather": "晴",
  308. "temp": "27",
  309. "img": "0"
  310. },
  311. {
  312. "time": "23:00",
  313. "weather": "晴",
  314. "temp": "26",
  315. "img": "0"
  316. },
  317. {
  318. "time": "0:00",
  319. "weather": "晴",
  320. "temp": "26",
  321. "img": "0"
  322. },
  323. {
  324. "time": "1:00",
  325. "weather": "晴",
  326. "temp": "26",
  327. "img": "0"
  328. },
  329. {
  330. "time": "2:00",
  331. "weather": "晴",
  332. "temp": "26",
  333. "img": "0"
  334. },
  335. {
  336. "time": "3:00",
  337. "weather": "晴",
  338. "temp": "26",
  339. "img": "0"
  340. },
  341. {
  342. "time": "4:00",
  343. "weather": "晴",
  344. "temp": "25",
  345. "img": "0"
  346. },
  347. {
  348. "time": "5:00",
  349. "weather": "晴",
  350. "temp": "25",
  351. "img": "0"
  352. },
  353. {
  354. "time": "6:00",
  355. "weather": "晴",
  356. "temp": "26",
  357. "img": "0"
  358. },
  359. {
  360. "time": "7:00",
  361. "weather": "晴",
  362. "temp": "27",
  363. "img": "0"
  364. },
  365. {
  366. "time": "8:00",
  367. "weather": "晴",
  368. "temp": "27",
  369. "img": "0"
  370. },
  371. {
  372. "time": "9:00",
  373. "weather": "晴",
  374. "temp": "29",
  375. "img": "0"
  376. }
  377. ]
  378. }
  379. }

请注意!!免费版接口流量限制情况(每个用户ID):30次流控/分钟。


使用postman做接口

  1. 添加headers

image.png

  1. 添加请求 query信息

image.png

测试用例

整理测试点

postman-01基本使用 - 图3

编写测试用例

编号 模块 前置条件 请求方式 请求路径 请求参数 检查点(预期) 备注
001 天气预报 headers中添加 appcode用户认证 GET http://jisutqybmf.market.alicloudapi.com/weather/query city=上海 “status”: 0,
“msg”: “ok”,
“city”: “上海”,

需要注意的是:除了正常的业务场景需要进行测试,异常的业务场景也需要进行测试。用例中需要包含如下异常场景;

错误码 错误信息 描述
201 City and city ID and city code are empty 城市和城市ID和城市代号都为空
202 City does not exist 城市不存在
203 There is no weather information in this city 此城市没有天气信息
210 No information 没有信息

postman发送post请求

企业微信机器人自动发布消息接口

请求地址:https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=e7e82c31-2d04-4ca7-895e-936ae3df57c5
请求方式:POST
请求参数(headers):无
请求参数(query):无
请求参数(body):
数据类型:json类型

  1. {
  2. "msgtype": "text",
  3. "text": {
  4. "content": "上海今日天气:29度,大部分多云,降雨概率:10%",
  5. "mentioned_list":["wangqing","@all"],
  6. "mentioned_mobile_list":["13800001111","@all"]
  7. }
  8. }

body 中的参数说明

参数 是否必填 说明
msgtype 消息类型,此时固定为text
content 文本内容,最长不超过2048个字节,必须是utf8编码
mentioned_list userid的列表,提醒群中的指定成员(@某个成员),@all表示提醒所有人,如果开发者获取不到userid,可以使用mentioned_mobile_list
mentioned_mobile_list 手机号列表,提醒手机号对应的群成员(@某个成员),@all表示提醒所有人

响应结果

  1. {
  2. "errcode": 0,
  3. "errmsg": "ok"
  4. }

image.png

postman操作

image.png