jmeter--function test based on Http+json interface

Source: Internet
Author: User

jmeter--function test based on Http+json interface

The test project is called Smile_task, referred to as Sm_task. This is a Nodejs super simple Todo list,sm_task without any UI interface (pure interface), which is more suitable for learning about interface testing. However, before you perform the interface test, you need to install the Smile_task running environment:

    • Mysql
    • Node download. msi version, note the difference between 64-bit and 32-bit
    • CNPM (Chinese version of Nodejs Package manager)

Configuring the development environment

Install Coffee-script (the ultimate goal of the coffee-script syntax to write Javascript,coffee-script is to compile the Coffee-script script into JavaScript) and SEQUELIZE-CLI (Sequelize is an ORM library, through SEQUELIZE-CLI we can run the Migrate command globally sequelize)

CNPM install-g coffee-scriptcnpm install-g sequelize-cli

Clone Source and installation dependencies

git clone https://github.com/easonhan007/express_api_demo.gitcd express_api_demonpm install #or cnpm Install

Configuration database

    • Modifying the database configuration in Config/config.json
    • To create a database named Smile_task_development
Sequelize db:migrate

Run

NPM start

 

 

First, the API:

Smile_task provides some of the following APIs

1. No Authentication Required

    • Post/login Username/password # Login
    • Post/register Username/password/password_confirmation # User Registration

2. Need authentication

    • Get/api/tasks # get all the tasks
    • GET/API/TASTKS/:TASK_ID # Get the task with ID task_id
    • Post/api/tasks Title/desc # Creating a task
    • DELETE/API/TASKS/:TASK_ID # Delete a task with ID task_id
    • PUT/API/TASKS/:TASK_ID # Complete task with ID task_id
Second, jmeter example: 1. User Registration

1.1. Details of the step:

"" "1, create a new Build-web-test-plan, remove all components except the configuration component under the Thread Group 2, fill in the HTTP Request defaults smile_task server IP,PORT3, create a new random under the Threads group Variable Configuration components (name: username, Variable name:username, Output format:user_000, Minimum value:1, Maximum value:999) 4, Create a new transaction controller, name: case-registration 5, under the transaction controller, create a new HTTP request (name: registration, Path:/register, request parameters: Username: ${username}, Password: ${username}, Password_confirmation: ${username}) 6, add 1 View results tree under Thread Group (CTRL+9) 7, add 1 Debug Sample (ctrl+8) 8 under Thread Group, change all the values in the threads group to 1, click Run "" "

2.2.:

3, as shown, after the interface debugging is complete, you can add a post processor and an assertion under the HTTP request (you can also consider the case of some unusual scenarios):

The backend processor gets the user name:

Create a new JSON PATH postprocessor under "register" this HTTP request

    • Name: Gets the user name returned after successful registration
    • Variable names:returned_username
    • JSON Path Expressions:$.username
    • Match numbers:1
    • Default Value:NOT FOUND

Assertion 1 User name cannot be empty:

New JSR223 Assertion

    • Name: User name cannot be empty
    • Language:javascript
    • Script:
var returned_username = vars.get (' returned_username ');  if (Returned_username = = ' Not FOUND ') {    assertionresult.setfailure (true);    Assertionresult.setfailuremessage (' No user name returned ');  }

Assertion 2 returned incorrect user name:

New JSR223 Assertion

    • Name: The returned user name is incorrect
    • Language:javascript
    • Script:
var returned_username = vars.get (' returned_username '); var expected_username = Vars.get (' username '); if (returned_ Username! = expected_username) {    assertionresult.setfailure (true);    Assertionresult.setfailuremessage (' The user name returned is incorrect ');}

  

2. User Login

1. Details of the step:

"" "1, create a new transaction controller, name: cese-login 2, under the transaction controller, create a new HTTP request, name Login: (method: Post, Path:/login   parameter: username:username:${returned_ Username}, Password:${returned_username}) 3, add a post processor at login request: Josn Extractor (name: Get token, Variable names:returned_ Username, JSON Path expressions: $.username, Match numbers:1, default Value:not FOUND) 4, add 1 View results tree under Thread Group (CTRL+9) 5, Add 1 Debug Sample (ctrl+8) 6 under Thread Group, click Run ""

2.:

3. Create tasks, complete tasks, delete tasks, view all Tasks

1. Details of the step:

"" "The subsequent tasks require authentication (the token returned when the user logs in) in order to perform the task through the server's authentication, so it is necessary to set up a new HTTP header management to receive the Save token (Authorization:bearer ${login_ Token}) Create a task: 1. Create a new transaction controller, name: cese-creating TASKS2, new HTTP request under transaction controller, name Post tasks: (method: Post, Path:/api/tasks parameter: title:${__ RandomString (5, ABCDEFGHIJKLMNOPQRSTUVWXYZ)}, Desc:${__randomstring (Ten, ABCDEFGHIJKLMNOPQRSTUVWXYZ)}) 3, in post A new post processor is added under the tasks request: Josn Extractor (name: Get task ID, Variable names:task_id, JSON Path expressions: $.id, Match numbers:1, Default Value:not FOUND) 4, add 1 View results tree under Thread Group (CTRL+9) 5, add 1 debug Sample (ctrl+8) to complete task under thread Group: 1, create a new transaction controller, Name: cese-complete TASKS2, Under transaction controller, create a new HTTP request with the name put tasks: (method: Put, Path:/api/tasks/:${task_id}3, add 1 View results tree (ctrl+9) under Thread Group) 4, add 1 debug Sample under Thread Group ( CTRL+8) Delete Task: 1, create a new transaction controller, name: cese-Delete tasks2, under transaction controller, create a new HTTP request, name Delete tasks: (method: Delete, path:/api/tasks/:${task_id} 3. Add 1 View results tree (ctrl+9) 4 under Thread Group, add 1 Debug Sample (ctrl+8) under Thread group to see All tasks: 1, create a new transaction controller, name: cese-View all TASKS2, under Transaction controller, create a new HTTP request , Name Get tasks: (method: Get, Path:/api/tasks}3, add 1 View results tree under Thread Group (CTRL+9) 4, add 1 debug Sample (ctrl+8) "" Under Thread Group

2.:

PS: Authentication is off by default. Make sure that the statement in App.coffee is app.use(express_jwt(secret: jwt_secret).unless(path: [‘/register‘, ‘/login‘])) not commented, and then use coffee -c app.coffee recompile.

jmeter--function test based on Http+json interface

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.