IT培訓(xùn)網(wǎng)
IT在線學(xué)習(xí)
1、應(yīng)用場(chǎng)景
在APP測(cè)試中,經(jīng)常出現(xiàn)APP已開(kāi)發(fā)完成而接口代碼尚未開(kāi)發(fā)完成的情況,或者APP使用了第三方付費(fèi)接口,目前暫時(shí)沒(méi)有賬號(hào),在這些情況下,你如何完成APP測(cè)試呢?很顯然在這些情況下,我們必須想辦法模擬接口服務(wù)器返回接口數(shù)據(jù),才能完成我們的APP測(cè)試,fiddler為我們提供了模擬接口服務(wù)器的功能。
2、案例描述
案例:我們的APP使用了某天氣預(yù)報(bào)接口,其接口描述如下:
接口名稱(chēng):根據(jù)城市名查詢(xún)天氣
接口地址:http://v.juhe.cn/weather/index
返回格式:json/xml
請(qǐng)求方式:get
請(qǐng)求示例:http://v.juhe.cn/weather/index?cityname=%E8%8B%8F%E5%B7%9E&key=您申請(qǐng)的KEY
請(qǐng)求參數(shù)說(shuō)明:
返回?cái)?shù)據(jù)示例:
- {
- "resultcode": "200",
- "reason": "查詢(xún)成功!",
- "result": {
- "sk": { /*當(dāng)前實(shí)況天氣*/
- "temp": "21", /*當(dāng)前溫度*/
- "wind_direction": "西風(fēng)", /*當(dāng)前風(fēng)向*/
- "wind_strength": "2級(jí)", /*當(dāng)前風(fēng)力*/
- "humidity": "4%", /*當(dāng)前濕度*/
- "time": "14:25" /*更新時(shí)間*/
- },
- "today": {
- "city": "天津",
- "date_y": "2014年03月21日",
- "week": "星期五",
- "temperature": "8℃~20℃", /*今日溫度*/
- "weather": "晴轉(zhuǎn)霾", /*今日天氣*/
- "weather_id": { /*天氣唯一標(biāo)識(shí)*/
- "fa": "00", /*天氣標(biāo)識(shí)00:晴*/
- "fb": "53" /*天氣標(biāo)識(shí)53:霾 如果fa不等于fb,說(shuō)明是組合天氣*/
- },
- "wind": "西南風(fēng)微風(fēng)",
- "dressing_index": "較冷", /*穿衣指數(shù)*/
- "dressing_advice": "建議著大衣、呢外套加毛衣、衛(wèi)衣等服裝。", /*穿衣建議*/
- "uv_index": "中等", /*紫外線強(qiáng)度*/
- "comfort_index": "",/*舒適度指數(shù)*/
- "wash_index": "較適宜", /*洗車(chē)指數(shù)*/
- "travel_index": "適宜", /*旅游指數(shù)*/
- "exercise_index": "較適宜", /*晨練指數(shù)*/
- "drying_index": ""/*干燥指數(shù)*/
- },
- "future": [ /*未來(lái)幾天天氣*/
- {
- "temperature": "28℃~36℃",
- "weather": "晴轉(zhuǎn)多云",
- "weather_id": {
- "fa": "00",
- "fb": "01"
- },
- "wind": "南風(fēng)3-4級(jí)",
- "week": "星期一",
- "date": "20140804"
- },
- {
- "temperature": "28℃~36℃",
- "weather": "晴轉(zhuǎn)多云",
- "weather_id": {
- "fa": "00",
- "fb": "01"
- },
- "wind": "東南風(fēng)3-4級(jí)",
- "week": "星期二",
- "date": "20140805"
- },
- {
- "temperature": "27℃~35℃",
- "weather": "晴轉(zhuǎn)多云",
- "weather_id": {
- "fa": "00",
- "fb": "01"
- },
- "wind": "東南風(fēng)3-4級(jí)",
- "week": "星期三",
- "date": "20140806"
- },
- {
- "temperature": "27℃~34℃",
- "weather": "多云",
- "weather_id": {
- "fa": "01",
- "fb": "01"
- },
- "wind": "東南風(fēng)3-4級(jí)",
- "week": "星期四",
- "date": "20140807"
- },
- {
- "temperature": "27℃~33℃",
- "weather": "多云",
- "weather_id": {
- "fa": "01",
- "fb": "01"
- },
- "wind": "東北風(fēng)4-5級(jí)",
- "week": "星期五",
- "date": "20140808"
- },
- {
- "temperature": "26℃~33℃",
- "weather": "多云",
- "weather_id": {
- "fa": "01",
- "fb": "01"
- },
- "wind": "北風(fēng)4-5級(jí)",
- "week": "星期六",
- "date": "20140809"
- },
- {
- "temperature": "26℃~33℃",
- "weather": "多云",
- "weather_id": {
- "fa": "01",
- "fb": "01"
- },
- "wind": "北風(fēng)4-5級(jí)",
- "week": "星期日",
- "date": "20140810"
- }
- ]
- },
- "error_code": 0
- }
3、實(shí)現(xiàn)過(guò)程
上面的案例中,我們需要模擬接口服務(wù)器返回天氣信息來(lái)進(jìn)行APP測(cè)試,具體實(shí)現(xiàn)步驟如下:
(1)按照提供的“返回?cái)?shù)據(jù)示例”格式準(zhǔn)備好測(cè)試數(shù)據(jù),并保存為weather_response.json文件。
(2)打開(kāi)fiddler,開(kāi)啟自動(dòng)響應(yīng)功能,添加并編輯匹配規(guī)則,指定響應(yīng)文件,如下圖所示:
(3)在瀏覽器地址欄中輸入 http://v.juhe.cn/weather/index?cityname=北京&key=您申請(qǐng)的KEY 進(jìn)行效果測(cè)試,效果如下圖所示:
更多內(nèi)容
>>本文地址:http://nfbqydst.cn/zhuanye/2022/72189.html
聲明:本站稿件版權(quán)均屬中公教育優(yōu)就業(yè)所有,未經(jīng)許可不得擅自轉(zhuǎn)載。
1 您的年齡
2 您的學(xué)歷
3 您更想做哪個(gè)方向的工作?
07月15日Java
咨詢(xún)/試聽(tīng)07月15日Python+人工智能
咨詢(xún)/試聽(tīng)07月15日Web前端
咨詢(xún)/試聽(tīng)07月15日UI設(shè)計(jì)
咨詢(xún)/試聽(tīng)07月15日大數(shù)據(jù)
咨詢(xún)/試聽(tīng)07月15日Java
咨詢(xún)/試聽(tīng)07月15日Python+人工智能
咨詢(xún)/試聽(tīng)07月15日Web前端
咨詢(xún)/試聽(tīng)07月15日UI設(shè)計(jì)
咨詢(xún)/試聽(tīng)07月15日大數(shù)據(jù)
咨詢(xún)/試聽(tīng)