xmysql:可為MySql生成REST API的命令
目的:接口返回的數(shù)據(jù)與數(shù)據(jù)庫的數(shù)據(jù)進(jìn)行對比校驗(yàn)
參考文章:
https://blog.csdn.net/dev_csdn/article/details/78480522
https://www.npmjs.com/package/xmysql
安裝與用法
1瓜贾、npm install -g xmysql
2、xmysql -h 數(shù)據(jù)庫地址 -u 用戶名 -p 密碼 -d 數(shù)據(jù)庫名
出現(xiàn)如下報(bào)錯(cuò)信息:
image.png
解決方法:xmysql requires node >= 7.6.0 升級node.js
1汽馋、 sudo npm install n -g
2绑莺、sudo n stable
升級到最新版本即可
3逃延、重新執(zhí)行xmysql -h 數(shù)據(jù)庫地址 -u 用戶名 -p 密碼 -d 數(shù)據(jù)庫名
出現(xiàn)以下錯(cuò)誤
Error: getaddrinfo ENOTFOUND localhost
解決方法:
1卓囚、sudo vim /etc/hosts
2套鹅、按 **i** 進(jìn)入編輯模式站蝠,如果你的hosts文件最后一行有 **0.0.0.0 account.xxx.xxx**,在這一行的上一行輸入 **127.0.0.1 localhost**卓鹿;沒有菱魔,則在最后一行輸入**127.0.0.1 localhost**。
3吟孙、重新執(zhí)行以上語句即可
4澜倦、在postman 中訪問http://localhost:3000 請求方式:get
具體的API參考 https://www.npmjs.com/package/xmysql
image.png
5、舉個(gè)例子:獲取查詢出來的訂單tid的數(shù)據(jù)杰妓,與實(shí)際的值進(jìn)行對比藻治,驗(yàn)證是否一致
image.png
pm.test("Your test name", function () {
var onlineTradeNo = JSON.parse(responseBody);
var tidValue = onlineTradeNo[0].tid;
pm.expect(tidValue).to.eql("訂單號(hào)數(shù)據(jù)");
});