1、簡介
MeterSphere是一站式開源持續(xù)測試平臺,涵蓋測試跟蹤、接口測試、性能測試、團(tuán)隊(duì)協(xié)作等功能,兼容JMeter 等開源標(biāo)準(zhǔn),有效助力開發(fā)和測試團(tuán)隊(duì)充分利用云彈性進(jìn)行高度可擴(kuò)展的自動化測試,加速高質(zhì)量軟件的交付。
2、安裝部署
環(huán)境要求
- 操作系統(tǒng): 任何支持 Docker 的 Linux x64
- CPU/內(nèi)存: 4核8G
- 磁盤空間: 20G
- 可訪問互聯(lián)網(wǎng)
安裝
以 root 用戶 ssh 登錄目標(biāo)服務(wù)器, 執(zhí)行如下命令
curl -sSL https://github.com/metersphere/metersphere/releases/latest/download/quick_start.sh | sh
安裝腳本默認(rèn)使用 /opt/metersphere 目錄作為安裝目錄,MeterSphere 的配置文件、數(shù)據(jù)及日志等均存放在該安裝目錄
更新
如果您的服務(wù)器可以訪問互聯(lián)網(wǎng), 可以通過以下命令直接升級 metersphere 至最新版本
# 升級至最新版本
msctl upgrade
# 查看 MeterSphere 狀態(tài)
msctl status
# 配置變動后重啟
systemctl restart docker
msctl reload
自 MeterSphere v1.3.0 起之后的版本才提供 upgrade 命令
更新說明
https://metersphere.io/docs/about/changelog/
登錄使用
安裝成功后,通過瀏覽器訪問如下頁面登錄 MeterSphere
地址: http://目標(biāo)服務(wù)器IP地址:8081
用戶名: admin
密碼: metersphere
登錄超時(shí)配置
vim /opt/metersphere/conf/metersphere.properties
添加以下配置,單位秒
session.timeout=86400
重啟ms-data-streaming服務(wù)
docker restart CONTAINER ID
日志查詢
docker logs ms-server
docker logs ms-data-streaming
docker logs ms-node-controller
docker logs mysql
docker logs kafka
3、接口測試
實(shí)際案例
- 創(chuàng)建項(xiàng)目

image

image
- 上傳jar包

image
- 項(xiàng)目環(huán)境配置

image

image
- 接口定義-導(dǎo)入已有,支持多種數(shù)據(jù)格式導(dǎo)入
備注:jmeter中腳本編寫不太規(guī)范的話,導(dǎo)入可能會提示找不到引用的jar包方法

image
- 接口定義-手動創(chuàng)建

image

image
- 添加接口用例

image
- 完善用例(可根據(jù)接口定義增加接口異常流)

image
- 接口用例可添加前后置腳本、斷言、參數(shù)提取等

image

image
- 前后置腳本,與Jmeter一樣
import com.xdja.wch.DFSBase;
DFSBase dfsBase = new DFSBase();
//獲取fastdfs服務(wù)器系統(tǒng)時(shí)間
log.info("-----timestamp------:"+"${timestamp}");
Long timestamp1 = Long.parseLong("${timestamp}");
//log.info("-----timestamp1------:"+ timestamp1);
Long time = timestamp1 + 8460000;
String ts = String.valueOf(time);
vars.put("ts",ts);
String data = "${name}" + ts + "${appId}";
String sign = dfsBase.hamcsha1(data, "123456");
//log.info("-----sign------:"+sign);
vars.put("sign",sign);

image
- 接口自動化-創(chuàng)建場景

image
- 接口自動化-場景中導(dǎo)入接口用例,建議引用方式,方便維護(hù)

image
- 接口自動化-場景中用例調(diào)試,微調(diào)用例順序

image

image
- 接口自動化-復(fù)制場景用例(準(zhǔn)生產(chǎn)環(huán)境復(fù)用測試環(huán)境接口場景用例)

image

image
4、Jenkins集成
安裝插件
https://github.com/metersphere/jenkins-plugin
- 下載jenkins-plugin插件metersphere-jenkins-plugin.hpi
- Jenkins安裝插件

image
- 創(chuàng)建項(xiàng)目-API Keys由MeterSphere進(jìn)行配置

image
- API Keys

image
- 執(zhí)行方式-測試計(jì)劃

image
- 執(zhí)行方式-性能測試場景、接口測試場景或者單接口定義

image

image

image
- 開始執(zhí)行

image

image
- 郵件通知

image
- 報(bào)告展示

image
5、性能測試
實(shí)際案例
- 創(chuàng)建性能測試

image
- 引用接口測試場景

image

image
- 壓力配置

image
- 高級配置

image
- 保存并執(zhí)行,可再次執(zhí)行、導(dǎo)出報(bào)告、下載JTL

image
- 可查看請求統(tǒng)計(jì)、錯(cuò)誤記錄、日志詳情等

image
6、問題處理
消息通知
- 郵件測試連接可以正常收到通知郵件,但是接口自動化執(zhí)行成功后未收到郵件
[root@xdja metersphere]# cd /opt/metersphere/logs/metersphere
[root@xdja metersphere]# tail -2000f error.log
# 發(fā)現(xiàn)如下報(bào)錯(cuò)信息
2021-04-15 10:55:01,122 [Async-Executor4] ERROR i.m.n.sender.impl.MailNoticeSender ? - Method[send][org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: STARTTLS is required but host does not support STARTTLS. Failed messages: javax.mail.MessagingException: STARTTLS is required but host does not support STARTTLS; message exceptions (1) are:
Failed message 1: javax.mail.MessagingException: STARTTLS is required but host does not support STARTTLS]
- 系統(tǒng)設(shè)置-郵件設(shè)置,將開啟TLS(如果SMTP端口是587,通常需要啟用TLS)勾選去掉,即可正常收取通知郵件

image
性能測試報(bào)錯(cuò)
- 首次執(zhí)行性能測試報(bào)如下錯(cuò)誤

image
Check node-controller /etc/hosts, 127.0.0.1 ${hostname} must be contained. Please delete the report and rerun.
- 在部署 node-controller 的機(jī)器上,使用hostname命令獲取主機(jī)名
[root@xdja ~]# hostname
xdja
[root@xdja ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
- 將獲取到的主機(jī)名xdja配置到 /etc/hosts 文件中,配置完成效果如下
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
127.0.0.1 xdja
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
性能測試結(jié)果偏差
- MeterSphere與原生Jmeter對同一接口性能測試,結(jié)果差距較大

image
- 已提交Issues
7、使用感受
- 開源、高度集成、所使用的技術(shù)棧適合二次開發(fā)
- 整套流程相對符合使用習(xí)慣,便于不同技術(shù)水平的同事上手
- 可以將零散的Jmeter接口用例統(tǒng)一維護(hù)管理起來,便于協(xié)作、評審、復(fù)用,提升效能
- 項(xiàng)目測試進(jìn)度可視化,便于度量接口測試質(zhì)量
- 可以較好的集成Jenkins實(shí)現(xiàn)自動化
- 部分頁面易用性差
- 性能測試結(jié)果與原生Jmeter存在差距