Python Interface Automation test (preparation of the C test environment)

Source: Internet
Author: User
Tags virtual environment virtualenv jmeter tutorial

Interface testing in a number of ways, such as can be used tools (Jmeter,postman), or can write their own code for interface testing, the use of tools relatively simple, the focus is to understand the project interface protocol is what, and then targeted to choose, You need to develop your own tools even when they are not well suited to your project.

In the early days of our project, we used JMeter for interface testing, when we felt that the tool was easy to use, that the team members had low learning costs, and that the scripting of the interface tests could be used for performance testing. For this tool I have also organized a system of articles to help the team's students get started using: JMeter Tutorial index stickers.

However, as the size of the project and the number of teams continue to grow, this tool will not be able to adapt to the current project needs, so our project has also re-developed the relevant interface Automation platform. But, but ... May be I let everyone poisoned too deep, now many classmates a mention interface Test Association to JMeter, for this, I deeply feel uneasy. After all, JMeter is just a tool for a different project. Can you still play the interface test? What is the difference between a session and a cookie? How is the tool implemented?

In order to let everyone in-depth mastery of the interface test, very early in the intention to write some simple code to do interface testing of the introductory tutorial, because you have to write the code has a lot of problems you need to deal with, such as how to save the session, interface dependencies on how to handle the case, how to manage and execute the order, Test data How to manage the problem, this process also helps us to understand the interface test and the HTTP protocol more deeply. OK, so much nonsense, let's get down to it.

This article mainly uses the Python language, Python in the HTTP protocol interface related library has the URLLIB,URLLIB2 and the Reqeusts library, which reqeusts the library to use the most convenient, Therefore I also mainly uses the requests library to do the HTTP protocol interface test. Let's start by looking at what environment information is needed:

First, install Python

The Mac comes with Python installed, and that's not much to say.

Second, install the virtual environment:

We can install multiple versions of Python on a single machine, in order to keep each version of the environment undisturbed, you can install the virtual environment, the installation method is as follows:

1, installation Virtualenv:pip install Virtualenv

2. Create a new virtual environment named Venv: Virtualenv venv

3. Enter the new environment: source Venv/bin/activate

4. Exit: Deactivate


Third, install requests library:

>>>PIP Install Requests

PS: the interface test using Python for HTTP protocol will use this library.

Iv. HTTP Test Tools:

An HTTP request and response service written using Python + Flask, which is primarily used to test HTTP libraries. Follow-up tests are based on this site.

http://httpbin.org/

Five, the local construction Httpbin:

Considering the testing to continue to visit the Httpbin website, request too much worry to be pulled to the blacklist, we build a set of Httpbin service in this blog.

1. Installation: Pip install Gunicorn

2. Installation: Pip install Httpbin

3, start: Gunicorn Httpbin:app

At this point, the environment has been completed, you can start to play ~

Python Interface Automation test (preparation of the C test environment)

Related Article

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.