xmysql:可為MySql生成REST API的命令
目的:接口返回的數(shù)據(jù)與數(shù)據(jù)庫的數(shù)據(jù)進(jìn)行對(duì)比校驗(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 升級(jí)node.js
1、 sudo npm install n -g
2、sudo n stable
升級(jí)到最新版本即可
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)行對(duì)比,驗(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ù)");
});