12. Jmeter- assertion

jmeter- assertion introduction and use

Performance tests less frequently used assertions. Assertion will increase the script execution time, but the interface testing assertion is a must. What is asserted? In fact, functional testing often said the expected and actual results are equal.

  • In response to the assertion

Figure know Italian. Interface test less frequently used.

  • JSON Assertion

Figure know it can be considered Italian. It should be note
Additionally the Assert value : equal to a certain value
Match AS Regular expression The : in line with regular expressions

  • Size Assertion

Figure know Italian. . .

  • JSR223 Assertion

JSR223 Assertion languages ​​may be selected, as shown below:

The author is commonly used beanshell and JS. Here we have an example to beanshell.
JSR223 Assertion examples


import org.json.*;

//获取上一个请求的返回值
String response = prev.getResponseDataAsString();
//将返回值转换为json
JSONObject responseJson = new JSONObject(response);
//获取responseMessage
String status = responseJson.get("status").toString();
String message = responseJson.getString("message");



if(!status.equals("0")) {
    Failure = true; 
    FailureMessage = "status错误";
}else{
    FailureMessage = "status正确";
    }

if(!message.equals("username or password error")) {
    Failure = true; 
    FailureMessage = "message错误";
}else{
    FailureMessage = "message错误";
    }

operation result

  • XPath Assertion

You can refer 11. Jmeter- postprocessor two XPath Extractor in

  • Compare Assertion

Ok. . Regular use of. Skip.

  • Assertion Duration

This is better understood. Assertion sampler consumed to run the test of time, such as 10 to fill our duration, if the actual time is 20s, then the assertion will fail.

  • HTML Assertion

  • MD5Hex assertion

MD5 returned to assert directly can fill.

  • SMIME Assertion

You can refer SMIME Assertion , much use.

  • XML assertions

Used to verify that the response data is correct XML format is not used.

  • XML Schema Assertion

  • BeanShell assertion
    can refer JSR223 Assertion , BeanShell assertion is our common assertion.

Jane Wang address book software testing
software testing Wang blog address

Welcome attention to micro-channel public number: Wang software testing. Software testing exchange group: 809 111 560

Reprinted Please note that the source, thank you

Guess you like

Origin www.cnblogs.com/suim1218/p/11571125.html