Hello everyone, I am two black, here is a set of software testing related resources:

  • Software testing related tools
  • Software testing practice set
  • Deep automated testing
  • Python Learning Guide
  • Python coding specification
  • Interview questions and resume templates

Pay attention to my public number: [programmer two black] can be free!

Communication group: 642830685

1. Development environment

  • Operating system: Ubuntu18

  • Development tool: IDEA+PyCharm plug-in

  • Python version: 3.6

2. Modules used

  • Requests: Used to send requests

  • XLRD: Operate Excel and organize test cases

  • Smtplib, email: Sends a test report

  • Logging: Log tracing

  • Json: data formatting

  • Django: Interface development

  • Configparser: Reads the configuration file

3. Frame design

3.1, process,

Interface use cases are organized in Excel, defining the URL, Request Body, and so on. The execution process is as follows:

  • Use the XLRD tool to read information in Excel and splice it into complete requests.

  • The interface request class receives a complete request to execute, this process needs to log, each execution should be traceable.

  • Backfill test results, send emails, and archive the results of each run. A better way is to do a historical performance report, more intuitive.

Advantages:

  • Use cases are organized by Excel, no code is required, and it is easy to get started.

  • In the case of a small number of use cases, the development speed is fast.

Disadvantages:

  • Use case dependencies are pain points.

  • Only interface automation use cases are supported.

  • Excel use cases can’t be pre-checked for correctness, you have to run them.

  • Unable to manage a large number of use cases well and not supporting collaborative team work, individual regression testing or post-live smoke testing can be a good choice.

Through the advantages and disadvantages of the contrast, it can be found that the framework of the bruise is actually a lot. So neither the industry’s open source automated test frameworks nor the enterprise’s own have seen use cases organized in Excel. It is worth mentioning that individual enterprises develop their own automation frameworks that are difficult to use, or simply combine a bunch of tools together. Does nothing to improve team productivity. However, a good product is not achieved overnight, it needs a continuous optimization process. So the framework above for organizing use cases in Excel is worth playing around with, so let’s call it Apitest. At present, there are unitTest, Testng, PyTest and so on.

3.2 Project structure

  • Testcase: json file that stores test cases or requests.

  • Config: indicates the configuration file.

  • Report: Test reports and log files and their archives.

  • Untils: Toolset, send_request for sending requests, email_tool for sending emails, excel_tool for reading Excel data, check_result for verifying results, run_main entry for use case execution, and log_trace for tracing logs.

4. Log printing

Use the built-in logging module to record run logs and set the log level.

log_trace.log:

import  logging

filename = ".. /report/test_case_run.log"

logging.basicConfig(level=logging.INFO,

format='%(asctime)s %(levelname)s1 %(filename)s [line:%(lineno)d] %(message)s',

datefmt='%a, %d %b %Y %H:%M:%S',

filename=filename,

filemode='w')
Copy the code

5. Interface request class encapsulation

Install the third-party module Requests

pip install requests
Copy the code

Define send_request to call get, POST, delete, put and other methods of request to send the request according to the incoming method type. send_request.py:

import  requests

from untils. log_trace importDef get_request(url,data=None,headers=None): res = requests. Get (url=url,data=data,headers=headers)returnDef request(url,data,headers=None): res = requests. Post (url=url,data=data,headers=headers)returnRes # to senddeleteDef del_request(URL,data=None,headers=None): res = requests.delete(url,data=data)

returnDef put_request(url,data,headers=None): pass def put_request(method,url,data=None,headers=None): logging.info(headers)if headers:

if method == "GET":

return get_request(url,data,headers=headers)

if method == "POST":

return post_request(url,data=data,headers=headers)

if method == "DELETE":

returnDel_request (URL,data=data,headers=headers) #put The request is not writtenif method == "PUT":

return  put_request(url,data=data,headers=headers)

else:

logging.info("Header is null")

except Exception as e:

logging.info("send request fail:%s"%e)
Copy the code

Write code to test the send_request method in untils_test.py as follows:

#coding:utf- 8 -

from untils.send_request import send_request

def test_send_request():

url="http://127.0.0.1:9000/articles/"

headers = {

"X-Token":"0a6db4e59c7fff2b2b94a297e2e5632e"

}

res = send_request("GET",url,headers=headers)

print(res.json())

if __name__ == "__main__":

test_send_request()
Copy the code

Running results:

/usr/bin/python36. /home/stephen/IdeaProjects/apitest/untils/untils_test.py

{'status': 'BS.200'.'all_titles': {'amy1': 'alive'.'modifytest': 'alive'.'addTest': 'alive'}, 'msg': 'query articles sucess.'}

Process finished with exit code 0
Copy the code

Finally, in order to facilitate everyone’s learning test, we specially prepared a 13G super practical dry goods learning resources, involving very comprehensive content. Include software learning roadmap, video, and more than 50 days of class 16 assault on practical projects, more than 80 software testing with software, 37 test documentation, 70 software test related issues, 40 level testing experience article, thousands of test questions, sharing, and 2021 bible software testing interview, there are all kinds of selected software testing job resume, Hope to help you…

Pay attention to my public number: [programmer two black] can get this information!

Recommended reading

Well paid programmers can’t escape being 35… How can we save ourselves when our abilities are out of sync with our age

Graduated from college and started selling… Unwilling to accept the status quo, the road to self-help testing

From crown to unemployment, finally choose software testing, looking back on the road, I was lucky!