JMeter Interface test Case Practice (i)

Source: Internet
Author: User

1.1. Introduction of the interface

The interface of this test is tested with the Address Book query interface in intranet, the interface parameters are as follows:

1.2. Use JMeter for interface test 1.2.1. Open JMeter

After downloading the JMeter, double-click the Jmeter.bat file in the bin directory:

1.2.2. Adding a thread group

On the test plan, right-click Add-->threads (Users)--thread group, add Test Scene settings component, interface test is generally set to 1 "threads", according to the number of test data set "number of cycles"

1.2.3. Adding HTTP request default values

Component, right-click on the thread group in the previous step and configure the component-->http request default value

When all the interface test access domain name and port are the same, you can use the component, once the server address changes, only need to modify the request default value.

1.2.4. HTTP request Constructs

Right-click on "Thread Group" to add-->samlper--> "HTTP request"

In the HTTP Request Settings page, enter the details of the interface being tested, including the request path, the corresponding request method, and the list of parameters sent along with the request, configured as follows:

1.2.5. Test report Configuration

View the results tree, view results in a table, Summary report three results in the "thread group" right-to-add listener

After you click Run, you can see the results of the operation, as follows:

From the above results can be seen, the use of "XX" test, the results returned two, in addition to the return data display, in addition to the above-mentioned default text form, you can also choose HTML form, more intuitive, as follows:

Another table to see the results, choose a display, as follows

1.2.6. Input partial parameterization

In the actual test, it is impossible to query the value of the test one input value, there are other test data, so introduce the concept of parameterization, let a use case loop execution, until all test data are tested, the following example:

There are 4 methods for parameterization of JMeter, this example only describes the most common and simple 1 methods, CSV file import configuration

1. Prepare the parameter file

2. Configure CSV Data Settings configuration item: Thread Group Right-click Add-config component-->csv Data set config

3. Modify the HTTP request constructed in 3.2.4: Username modified as parameter, referenced from CSV file

4. Modify the test plan to make the script repeat

5, after the operation, you can see the results are as follows:

1.2.7. Extracting content from response results, asserting

The results above will always be correct, as long as the request is successful and no assertion is made on the returned result, this example describes the assertion setting

1, Regular expression extract content: Extract content from the response content and file extraction content comparison, this example uses the comparison result is: Employee number

On the HTTP request for address Book queries, right-click on the post-processor-to-regular expression extractor, configured as follows:

For rules on regular expressions, find your own document learning, where you can extract the employee number that returns Nie Rong Nyainrong and refer to it as the test parameter.

2. Add Assertion: Compare the employee number read in the extracted employee number test to the CSV file to determine if the result is correct

On the HTTP request for address Book queries, right-click on the assertion-and-response assertion, configured as follows:

Thread Group Right-click Add-->sampler-->debug Sampler: Used to view the contents of a regular expression extract

3. After running, view the results

Found the second parameter use case execution result failed, expand, review the details of the response assertion, found that test does not match T123451, that is, the second tester's employee number is not T123451.

Next we look at the detailed response data to see where the problem is.

As can be seen, the second tester's employee number is T12345, not T123451, so the assertion does not pass.

In fact, this error is deliberately set incorrectly in the CSV document to verify the correctness of the assertion.

JMeter Interface test Case Practice (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.