Jmeter(JAVA):
1、 接口测试——自动化(界面、脚本、插件)
2、 性能测试——线程组(一个线程组对应一个虚拟用户)
问题:
Jmeter和loadrunner的区别:
1、 性能的结果展示(吞吐量、响应时间、事物、消息数)
2、 IP欺骗
3、 场景设置
学习方向:
1、 先掌握接口自动化的实现
2、 然后学习性能测试
线程组:
SetUp thread Group ——
teardown thread Group ——
线程组—— 与loadrunneraction
一个线程组可以理解成一个用例或者一个场景
例子:一个登录操作为例:
为了方便测试我们先用flask写个简单的服务(文末代码)作为服务器并启动;
case测试步骤:
1、 发送HTTP请求
建立HTTP请求;
运行后,jemter向服务端发送了请求,这时候服务端就会有响应;
2、 发送结果展示:
2.1、点击右上角的黄色的三角形的感叹号按钮,下方就会展示出log信息;
2.2、在注册步骤上右键,点击“添加——监听器——查看结果树”,设置保存路径,所有的请求结果都会展示在“查看结果树”中;
3、 断言
以下为server端:
# encoding=utf-8
from flask import Flask,request,make_response
import time
import random
app = Flask(__name__)
#注册
@app.route('/register',methods=["post"])
def register():
time.sleep(2)
userName=request.args.get("userName")
userPwd=request.args.get("userPwd")
return '{"result":"success","status":0,"message":"registersuccessfully"}'
#登录
@app.route('/login',methods=["post"])
def login():
time.sleep(2)
userName = request.args.get("userName")
userPwd = request.args.get("userPwd")
if str(userName).startswith("test") and str(userPwd).startswith("test"):
token="abcd"+str(random.randint(1,1001))
return '{"result":"success","status":0,"token":"'+token+'"}'
else:
return make_response('{"result":"failed","status":1,"message":"loginfailed"}',400)
#查询
@app.route('/query',methods=["get"])
def query():
time.sleep(2)
token = request.args.get("token")
if str(token).startswith("abcd"):
return '{"result":"success","status":0,"message":"querysuccessfully"}'
else:
return make_response('{"result":"failed","status":1,"message":"tokenis wrong"}',400)
#添加
@app.route('/add',methods=["POST"])
def add():
time.sleep(2)
token = request.args.get("token")
if str(token).startswith("abcd"):
return '{"result":"success","status":0,"message":"addsuccessfully"}'
else:
return make_response('{"result":"failed","status":1,"message":"tokenis wrong"}',400)
#修改
@app.route('/update',methods=["PUT"])
def update():
time.sleep(2)
token = request.args.get("token")
if str(token).startswith("abcd"):
return '{"result":"success","status":0,"message":"updatesuccessfully"}'
else:
return make_response('{"result":"failed","status":1,"message":"tokenis wrong"}',400)
#删除
@app.route('/delete',methods=["delete"])
def delete():
time.sleep(2)
token = request.args.get("token")
if str(token).startswith("abcd"):
return '{"result":"success","status":0,"message":"deletesuccessfully"}'
else:
return make_response('{"result":"failed","status":1,"message":"tokenis wrong"}',400)
if __name__ == '__main__':
app.run("0.0.0.0",port=8888,debug=True,threaded=True)