jmeter之断言
18.5.5 BeanShell Assertion |
||||||||||||||||||
The BeanShell Assertion allows the user to perform assertion checking using a BeanShell script. For full details on using BeanShell, please see the BeanShell website. Note that a different Interpreter is used for each independent occurence of the assertion in each thread in a test script, but the same Interpreter is used for subsequent invocations. This means that variables persist across calls to the assertion. All Assertions are called from the same thread as the sampler. If the property "beanshell.assertion.init" is defined, it is passed to the Interpreter as the name of a sourced file. This can be used to define common methods and variables. There is a sample init file in the bin directory: BeanShellAssertion.bshrc The test element supports the ThreadListener and TestListener methods. These should be defined in the initialisation file. See the file BeanShellListeners.bshrc for example definitions. Control Panel Parameters
There's a sample script you can try. Before invoking the script, some variables are set up in the BeanShell interpreter. These are strings unless otherwise noted:
The following methods of the Response object may be useful:
|
18.5.10 BSF Assertion |
||||||||||||||||||
The BSF Assertion allows BSF script code to be used to check the status of the previous sample. Control Panel Parameters
The script (or file) is processed using the BSFEngine.exec() method, which does not return a value. The following variables are set up for use by the script:
The script can check various aspects of the SampleResult . If an error is detected, the script should use AssertionResult.setFailureMessage("message") and AssertionResult.setFailure(true). For futher details of all the methods available on each of the above variables, please check the Javadoc |
8.5.12 Compare Assertion |
|||||||||||||||
Compare Assertion MUST NOT BE USED during load test as it consumes a lot of resources (memory and CPU). Use it only for either functional testing or during Test Plan debugging and Validation.
The Compare Assertion can be used to compare sample results within its scope. Either the contents or the elapsed time can be compared, and the contents can be filtered before comparison. The assertion comparisons can be seen in the Comparison Assertion Visualizer . Control Panel Parameters
|
8.5.7 HTML Assertion |
||||||||||||||||||||||||
The HTML Assertion allows the user to check the HTML syntax of the response data using JTidy. Control Panel Parameters
|
18.5.6 MD5Hex Assertion
The MD5Hex Assertion allows the user to check the MD5 hash of the response data.
Control Panel
Parameters
Attribute |
Description |
Required |
Name |
Descriptive name for this element that is shown in the tree. |
No |
MD5 sum |
32 hex digits representing the MD5 hash (case not significant) |
Yes |
18.5.3 Size Assertion |
|||||||||||||||
The Size Assertion tests that each response contains the right number of bytes in it. You can specify that the size be equal to, greater than, less than, or not equal to a given number of bytes.
Since JMeter 2.3RC3, an empty response is treated as being 0 bytes rather than reported as an error.
Control Panel Parameters
|
18.5.13 SMIME Assertion |
||||||||||||||||||
The SMIME Assertion can be used to evaluate the sample results from the Mail Reader Sampler. This assertion verifies if the body of a mime message is signed or not. The signature can also be verified against a specific signer certificate. As this is a functionality that is not necessarily needed by most users, additional jars need to be downloaded and added to JMETER_HOME/lib :
These need to be downloaded from BouncyCastle. If using the Mail Reader Sampler , please ensure that you select "Store the message using MIME (raw)" otherwise the Assertion won't be able to process the message correctly. Control Panel Parameters
|
18.5.9 XML Schema Assertion |
|||||||||
The XML Schema Assertion allows the user to validate a response against an XML Schema. Control Panel Parameters
|
18.5.4 XML Assertion |
||||||
The XML Assertion tests that the response data consists of a formally correct XML document. It does not validate the XML based on a DTD or schema or do any further validation. Control Panel Parameters ¶
|
18.5.8 XPath Assertion |
||||||||||||||||||||||||||||||||||||
The XPath Assertion tests a document for well formedness, has the option of validating against a DTD, or putting the document through JTidy and testing for an XPath. If that XPath exists, the Assertion is true. Using "/" will match any well-formed document, and is the default XPath Expression. The assertion also supports boolean expressions, such as "count(//*error)=2". See http://www.w3.org/TR/xpath for more information on XPath. Some sample expressions:
Control Panel Parameters
The non-tolerant parser can be quite slow, as it may need to download the DTD etc.
As a work-round for namespace limitations of the Xalan XPath parser implementation on which JMeter is based, you can provide a Properties file which contains mappings for the namespace prefixes:
You reference this file in jmeter.properties file using the property:
|
18.5.1 Response Assertion |
|||||||||||||||||||||
The response assertion control panel lets you add pattern strings to be compared against various fields of the response. The pattern strings are:
A summary of the pattern matching characters can be found at ORO Perl5 regular expressions. You can also choose whether the strings will be expected to match the entire response, or if the response is only expected to contain the pattern. You can attach multiple assertions to any controller for additional flexibility. Note that the pattern string should not include the enclosing delimiters, i.e. use Price: \d+ not /Price: \d+/ . By default, the pattern is in multi-line mode, which means that the "." meta-character does not match newline. In multi-line mode, "^" and "$" match the start or end of any line anywhere within the string - not just the start and end of the entire string. Note that \s does match new-line. Case is also significant. To override these settings, one can use the extended regular expression syntax. For example: (?i) - ignore case (?s) - treat target as single line, i.e. "." matches new-line (?is) - both the above These can be used anywhere within the expression and remain in effect until overriden. e.g. (?i)apple(?-i) Pie - matches "ApPLe Pie", but not "ApPLe pIe" (?s)Apple.+?Pie - matches Apple followed by Pie, which may be on a subsequent line. Apple(?s).+?Pie - same as above, but it's probably clearer to use the (?s) at the start. Control Panel Parameters
The pattern is a Perl5-style regular expression, but without the enclosing brackets. Assertion Examples
Figure 14 - Test Plan
Figure 15 - Assertion Control Panel with Pattern
Figure 16 - Assertion Listener Results (Pass)
Figure 17 - Assertion Listener Results (Fail)
|
18.5.2 Duration Assertion |
|||||||||
The Duration Assertion tests that each response was received within a given amount of time. Any response that takes longer than the given number of milliseconds (specified by the user) is marked as a failed response. Control Panel Parameters
|
源文档