Jmeter 是一款使用Java开发的,开源免费的,测试工具, 主要用来作功能测试和性能测试(压力测试/负载测试). html
并且用Jmeter 来测试 Restful API, 很是好用。正则表达式
第一步:新建线程组数据库
第二步:新建Http Request工具
第三步:添加http请求头oop
第四步:添加结果树视图性能
第六步:添加Assertion和Assert Results测试
选择HTTP Request, 右键 Add-> Assertions -> Response Assertion. 添加 Patterns To Test线程
而后添加一个Assetion Results 用来查看Assertion执行的结果. 3d
选中Thread Group 右键 Add -> Listener -> Assertion Results. code
运行后, 若是HTTP Response中没有包含期待的字符串。 那么test 就会Fail.
7 使用用户自定义变量
咱们还能够在Jmeter中定义变量。 好比我定义一个变量叫 city. 使用它的时候用 ${city}
添加一个 User Defined Variables. 选中Thread Group: 右键 Add -> Config Element -> User Defined Variables.
咱们添加一个变量: city
而后在Http Request中使用这个变量
第八步:关联
所谓关联, 就是第二个Requst, 使用第一个Request中的数据
咱们须要在第一个Http Requst 中新建一个正则表达式,把Response的值提取到变量中,提供给别的Http Request 使用
选择第一个Http Request, 右键 Add -> Post Processors -> Regular Expresstion Extractor
如今新建第二个Http Request, 发送到: http://www.weather.com.cn/weather2d/${citycode}.html
${citycode} 中的数据, 是从Regular Expression Extractor 中取来的
到这, 脚本就所有写好了, 运行下,看下最终结果
启动Jmeter, 先添加一个Thread Group, 而后添加一个CSV Data Set Config (Add -> Config Element -> CSV Data Set Config)
咱们添加http 请求,发送get 到 http://cn.bing.com/search?q=博客园+小坦克
选择Thread Group 右键 (Add ->Sampler -> HTTP Request), 须要填的数据以下:
选中Thread Group
Number of Threads(users): 一个用户占一个线程, 200个线程就是模拟200个用户
Ramp-Up Period(in seconds): 设置线程须要多长时间所有启动。若是线程数为200 ,准备时长为10 ,那么须要1秒钟启动20个线程。也就是每秒钟启动20个线程。
Loop Count: 每一个线程发送请求的次数。若是线程数为200 ,循环次数为10 ,那么每一个线程发送10次请求。总请求数为200*10=2000 。若是勾选了“永远”,那么全部线程会一直发送请求,直到选择中止运行脚本。
选中Thread Group 右键(Add -> Listener -> Summary Report)
到目前为止, 脚本就全写好了, 咱们来运行下, 如何看下测试的结果
使用jmeter对数据库压测:
http://www.cnblogs.com/chengchengla1990/p/5760692.html
参考 http://www.cnblogs.com/TankXiao/p/4045439.html