Jmeter测试结果分析这一篇,我打算分成上下两部分。上篇,主要讲述如何使用jmeter中Assertion对结果进行简单的分类;下篇,主要讲述的是当我们拿到测试结果后,我们应该如何去看待这些测试结果。

用过LoadRunner的人都知道,LoadRunner本身提供了很多函数可以对收集回来的结果进行一些初步的分析。例如可以做到判断返回的结果是否正确;判断request的response time是否大于x秒之类的。相比起LoadRunner,Jmeter在这方面没有那么强大,但是个人认为,对于一些编程基础不是太好的测试人员来说,Jmeter比LoadRunner易用性上面做得更出色。

Assertion--断言,通常是用于对每一个request sampler进行额外验证的工具。下面通过一个例子来介绍一下常用的几个Assertions。

假设现在要进行一个登陆的压力测试,下面是对pass的几个定义:

1.正确login后,必须收到返回的身份验证和用户个人信息下载的完成信息;

2.响应时间不能超过150毫秒

3.返回的结果大小不能小于750bytes

根据以上的要求,我们在对应的request sampler下面添加了以下的Assertions。

 

A.Response Assertion

 

 Response Field to Test -- 标示被检查对象是什么?

 Pattern Matching Rules -- 标明被检查对象与验证内容之间的关系,Contains(包含关系);Matches(匹配关系);Equals(相等关系);Not(非关系)

 Pattern to Test -- 需要验证的内容列表

B.Duration Assertion

 

 Duration to Assert -- 允许的响应时间的最大值

C.Size Assertion

 

 Size to Assert -- 对于返回结果文件大小的标准定义

 

二、结果分析

添加了以上的Assertions后,我运行了一次脚本。以下是存放结果的.jtl文件的内容:

timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,Latency
11/04/08 13:22:03,172,Do Login,200,OK,Thread Group 1-1,text,false,The operation lasted too long: It took 172 milliseconds, but should not have lasted longer than 150 milliseconds.,835,172
11/04/08 13:22:03,156,Do Login,200,OK,Thread Group 1-2,text,false,Test failed: text expected to contain /loginMsg="OK"/,633,156
11/04/08 13:22:03,156,Do Login,200,OK,Thread Group 1-3,text,false,The operation lasted too long: It took 156 milliseconds, but should not have lasted longer than 150 milliseconds.,839,156
11/04/08 13:22:03,156,Do Login,200,OK,Thread Group 1-4,text,false,The operation lasted too long: It took 156 milliseconds, but should not have lasted longer than 150 milliseconds.,836,156
11/04/08 13:22:03,78,Do Login,200,OK,Thread Group 1-5,text,true,,779,78
11/04/08 13:22:03,63,Do Login,200,OK,Thread Group 1-7,text,false,Test failed: text expected to contain /loginMsg="OK"/,570,63
11/04/08 13:22:03,141,Do Login,200,OK,Thread Group 1-6,text,false,The result was the wrong size: It was 721 bytes, but should have been greater than 750 bytes.,721,141
11/04/08 13:22:03,78,Do Login,200,OK,Thread Group 1-9,text,false,The result was the wrong size: It was 724 bytes, but should have been greater than 750 bytes.,724,78
11/04/08 13:22:03,204,Do Login,200,OK,Thread Group 1-10,text,false,The operation lasted too long: It took 204 milliseconds, but should not have lasted longer than 150 milliseconds.,1137,204
11/04/08 13:22:03,2985,Do Login,200,OK,Thread Group 1-8,text,false,Test failed: text expected to contain /loginMsg="OK"/,570,2985

我们可以看到,每一个Sampler都会经过Assertions的判断,只要有一个不符合条件的都会标示为False。

其实除了以上讲到Assertion,jmeter还提供了其他一些比较实用的Assertion,而我在这也不一一介绍了。

有兴趣的可以看一下jmeter的user manual,然后再自己动手试验一下。

<待续>

 

 

posted on 2008-11-05 22:55  Carrie  阅读(34361)  评论(6编辑  收藏  举报