"go" using Jmeter to do Web interface testing

Source: Internet
Author: User
Tags vars soapui

Recently summed up in the interface testing knowledge and experience, here to share with you, if there is said wrong place please correct ME.

Interface Test Overview definition

API testing is a type of software testing that involves testing application programming interfaces (apis) directly and as Part of integration testing to determine if they meet expectations for functionality, reliability, performance, and Securi Ty. Since APIs lack a GUI, API testing is performed at the message layer. [2] API testing is now considered critical for automating testing because APIs now serve as the primary interface to Appli Cation logic and because GUI tests is difficult to maintain with the short release cycles and frequent changes commonly u SED with Agile software development and DevOps).

Wiki Definition: the interface test as part of the integration test, through the direct control API to determine the functional, reliability, performance and security of the System. The API test is not interface-executed at the communication layer. API testing plays an important role in automated testing because APIs are typically the primary interface for application logic, and GUI testing is difficult to maintain in agile development and in fast iterations and frequent changes in devops.

Classification

Interface testing is a test of the interface between components of a test system. Interface testing is primarily used to detect the interaction points between external systems and systems, as well as within each subsystem. The focus of testing is to examine the exchange of data, the transfer and control of management processes, and the mutual logical dependencies between SYSTEMS. Interface testing is broadly divided into two Categories: module interface testing and web interface Testing.

Module Interface Test

Module interface testing is the basis of unit Testing. It mainly tests the call and return of the Module. It is often necessary to write some pile modules and drive Modules.
The main test points are as Follows:

Check that the data returned by the interface is consistent with the expected Results.
Check the fault tolerance of the interface, if it can be handled if the type of the data passed is Wrong.
The boundary value of the interface Parameter. For example, If the passed parameter is large enough or negative, the interface can be handled normally.
The performance of the interface, the time the interface processes the data is also a method of Testing. The internal algorithm and code optimization are Involved.
Security of the interface

Web Interface Testing

Web interface testing can be divided into two Categories: server interface testing and external interface Testing.

Server Interface Test: is the interface between the test browser and the Server. User input data is input to the front-end page, how to transfer the data in the background? The Get and post requests for the HTTP protocol are implemented to achieve data transfer at the front and back ENDS. This can also be considered an interface Test.
External interface Testing: This is a typical example of third-party payments, such as in our application, when the charge is charged, the Third-party payment interface will be Called.

The main test points are as Follows:

The request is correct, the default request succeeds 200, and if the request error can return 404, 500, and so On.
Check the correctness and format of the returned data; JSON is a very common format.
The security of the interface, the general web will not be exposed to any online call, need to make some restrictions, such as authentication or Authentication.
The performance of the interface, which directly affects the user Experience.

Interface Test Tools

SOAPUI
Jmeter
Grinder
Suds Python

The main application of SOAPUI and JMeter in the Work. SOAPUI has better support for interface security Testing. This article is mainly about the use of jmeter, the focus is on functional testing, for its strengths performance testing, described in a future article.

Test Case design and principles

Because the interfaces tested in the actual work are based on the HTTP protocol, the following test cases and principles are also for such interfaces.

Test Cases

Positive test Cases:

    • Overwrite all required parameters

    • Combining optional parameters

    • Parameter boundary value

    • If the value range of the parameter is an enumeration variable, all enumerated values need to be overwritten

    • You should also consider the actual business application scenario to design the combination of input Parameters. (these use cases can be used to test functionality as smoke use Cases.) It can also be used in the future to simulate actual business scenarios for stress testing, but be careful to ensure the independence of use cases, because stress testing is multithreaded. For example, we test account creation interface, name is not heavy, when writing a test case, the name can be assigned to a time stamp, so that the use case in multi-threaded concurrency test is not a Problem)

Negative Test Cases:

    • Empty data

    • Contains special characters

    • Data out of bounds

    • The wrong data

Verification Point:

    • Status code (under normal circumstances, all requests should return 200)

    • Response information data structure (most of the time, The return information is json, we should verify the corresponding structure when the data information changes)

    • Verify the type of node

    • Verify the value of the node (mainly for fixed values or values following certain rules, we can know the expected Result)

    • For lists, You should also verify that the length of the list is consistent with the expected value based on the request Parameters.

    • Negative test cases, You should verify that error info matches the actual

Testing principles

Tests should be self-contained, readable, variable, and maintainable, which is the principle that all automated tests should follow.

    • Each test case is independent

    • Test cases are repeatable (this means that some test data cannot be written to death, and different environmental data may be different.) In the actual work, the solution has two: self-created the required data, such as you want to test the interface requires input parameter accountid, you can call the Create account API, and then from the response value to get accountid, when you test the interface you want to measure, Then delete the new account, which means a test case is divided by three steps. Another way is to read the database, from the database to obtain data, this method in the test development and test environment is ok, but if the line of the environment is more difficult, because we can not arbitrarily update the above data, and can not put too much test data on it. So I personally prefer the first method, although increase the workload of development cases, but once and for All)

    • Testing can be run in different environments (the normal test environment will be at least divided dev/test/staging/online, we in the test process, we should put the domain name, token/apikey, etc. should be placed in a variable, when switching environment, we only need to change the value of the variable can be

    • Test data is decoupled from the business (test data includes parameter interface Data/system data required for test Execution)

    • Try to unify common test environment variables

    • After the test is complete, delete the unnecessary test Data.

JMeter use

In the actual work, I mainly apply jmeter to the interface to do functional testing, so the following mainly introduce the use of JMeter

Basic introduction

Here is a test script for me, usually a file containing the following Components. I use the simple controller and debug sampler to organize the management of different interfaces, the verification point mainly by writing some BeanShell scripts to Achieve. For some complex operations, if available resources are found on the web, such as jar,class files are referenced directly in BeanShell Preprocessor/postprocessor. In addition, writing BeanShell in JMeter is not easy to debug, so it is recommended that complex features be written directly in Eclipse and then build the jar Package. About BeanShell use will be introduced in the following

Using BeanShell in JMeter

BeanShell is a scripting language that fully conforms to the Java syntax specification and has its own syntax and methods [official website] (http://www.beanshell.org/)
Almost all of my scripts are validated through BeanShell scripts, and only a few have response Assert Applied.

BeanShell Common Built-in variables

(http://jmeter.apache.org/api/org/apache/jmeter/threads/)

Here are some practical examples

    • Action Variable: (vars)

    • Gets the information returned by the previous sample (prev)

    • Write information to the Jmeter.log file

Log.info ("log Information")

    • Get Property (props)

It is similar to vars, and the corresponding properties are defined in the file jmeter.properties

    • referencing external files (jar/class/java)


In addition, if you reference an external jar package, you can also configure it in test plan, click the test Plan node in jmeter, and you will see the following interface to add the path of the jar package directly.

Other CSV configuration components use

Csv_data_set_config when sending multiple sets of the same request, but with different parameters, this configuration component can be added


The above variables can then be used with the loop controller in the sampler

Connecting to a database

During the testing process, we need some test data from the database, when we need to connect the database in JMeter
The following is an example of a MySQL database connection

    • Download MySQL JDBC driver from (http://dev.mysql.com/downloads/connector/j/5.1.html)

    • Copy this file to the "lib" folder under the JMeter installation path

    • Establish "JDBC Connection configuation"


For additional database connections please refer to:

    • Add JDBC Request


Because we are in the interface test, more time is to obtain the data, so basically use "select". If you want to insert data, you need to select "callable Statement" in "Query Type"

The following points are noted in the use Process:

    • SQL statements do not add semicolons

    • If the query condition is a variable, in the statement "?" Value in the following "Parameters value" definition, if there are multiple parameters, the middle is separated by semicolons. of course, You can also use the ${variable name} (defined in the user-defined variables Component)

    • You can set how many variables you have in the "variable names" datasheet, and a comma placeholder for columns that do not need to be set.

    • For more specific use details please refer to (http://jmeter.apache.org/usermanual/component_reference.html#JDBC_Request)

    • Get query result data in BeanShell

Add Listener
    • View result Tree

    • Aggregate Report

Aggregate report is a commonly used listener in Jmeter, which is translated into "aggregated reports", each of which is indicated BELOW.

Jmeter and Jekins Integration

Just talk about it. how to execute jmeter at the command line

    • First configure the Jmeter_home environment variable, the value is you jmeter decompression path

    • Run jmeter-v on the command line, return to the current version correctly, prove environment OK

    • Run Jmeter-n-t script.jmx-l LOG.JTL

The next thing, lose classmate has recommended a link (https://testerhome.com/topics/2580), I think has fully explained the problem, so here is no longer detailed.

"go" using Jmeter to do Web interface testing

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.