GO based on the development of open source API testing tools, support HTTP/WebSocket/RPC and other protocols

GO based on the development of open source API testing tools, support HTTP/WebSocket/RPC and other protocols

2022-12-12 0 1,135
Resource Number 49399 Last Updated 2025-02-21
¥ 0USD Upgrade VIP
Download Now Matters needing attention
Can't download? Please contact customer service to submit a link error!
Value-added Service: Installation Guide Environment Configuration Secondary Development Template Modification Source Code Installation

GO based on the development of open source API testing tools, support HTTP/WebSocket/RPC and other protocols

8a02752413344ec491eb14d26871da35noop.image_

HttpRunner is an open source API testing tool that supports HTTP(S)/HTTP2 / WebSocket/RPC and other network protocols, covering interface testing, performance testing, digital experience monitoring and other test types. Simple to use, powerful, with a rich plug-in mechanism and a high degree of scalability.

119354f983e54c038a5923c86e6770banoop.image_

Functional characteristics

  • Network protocol: Full support for HTTP(S)/HTTP2/WebSocket, extensible support for TCP/UDP/RPC and other protocols
  • Multi-format optional: The test case supports YAML/JSON/go test/pytest format, and supports format conversion
  • Dual execution engine: Support golang/python two execution engines, both the high performance of go and the rich ecology of pytest
  • Recording & Generation: Use HAR/Postman/Swagger/curl to generate test cases; Method prompts based on chain calls can also be used to quickly write test cases
  • Complex scene: based on the variables/extract/validate/hooks mechanism can easily create arbitrarily complex test scenarios
  • Plug-in mechanism: Built-in rich function library, while you can write custom functions based on mainstream programming languages (go/python/java) to easily achieve more capabilities
  • Performance testing: Stress testing can be implemented without additional work; Single machine can easily support 1w+ VUM, combined with distributed load capacity to achieve massive voltage generation
  • Network performance collection: On the basis of scenario-based interface testing, additional network link performance indicators (DNS resolution, TCP connection, SSL handshake, network transmission, etc.) can be collected.
  • One-click deployment: The binary command line tool is used to quickly install and deploy macOS, Linux, or Windows devices without environment dependence

Installation and deployment

Developed by Golang, HttpRunner has pre-compiled binary files for mainstream operating systems, and can be installed and deployed by executing a command in the system terminal.

$ bash -c "$(curl -ksSL https://httprunner.com/script/install.sh)"

After the command succeeds, you will get an hrp command line tool, run hrp -h to view the parameter help description.

$ hrp -h

██╗  ██╗████████╗████████╗██████╗ ██████╗ ██╗   ██╗███╗   ██╗███╗   ██╗███████╗██████╗
██║  ██║╚══██╔══╝╚══██╔══╝██╔══██╗██╔══██╗██║   ██║████╗  ██║████╗  ██║██╔════╝██╔══██╗
███████║   ██║      ██║   ██████╔╝██████╔╝██║   ██║██╔██╗ ██║██╔██╗ ██║█████╗  ██████╔╝
██╔══██║   ██║      ██║   ██╔═══╝ ██╔══██╗██║   ██║██║╚██╗██║██║╚██╗██║██╔══╝  ██╔══██╗
██║  ██║   ██║      ██║   ██║     ██║  ██║╚██████╔╝██║ ╚████║██║ ╚████║███████╗██║  ██║
╚═╝  ╚═╝   ╚═╝      ╚═╝   ╚═╝     ╚═╝  ╚═╝ ╚═════╝ ╚═╝  ╚═══╝╚═╝  ╚═══╝╚══════╝╚═╝  ╚═╝

HttpRunner is an open source API testing tool that supports HTTP(S)/HTTP2/WebSocket/RPC
network protocols, covering API testing, performance testing and digital experience
monitoring (DEM) test types. Enjoy! 

License: Apache-2.0
Website: https://httprunner.com
Github: https://github.com/httprunner/httprunner
Copyright 2017 debugtalk

Usage:
  hrp [command]

Available Commands:
  boom         run load test with boomer
  completion   generate the autocompletion script for the specified shell
  convert      convert JSON/YAML testcases to pytest/gotest scripts
  har2case     convert HAR to json/yaml testcase files
  help         Help about any command
  pytest       run API test with pytest
  run          run API test with go engine
  startproject create a scaffold project

Flags:
  -h, --help               help for hrp
      --log-json           set log to json format
  -l, --log-level string   set log level (default "INFO")
  -v, --version            version for hrp

Use "hrp [command] --help" for more information about a command.

Scaffold creation project

HttpRunner supports the use of scaffolding to create sample projects.

Run the hrp startproject command to initialize a project with a specified name.

$ hrp startproject demo
10:13PM INF Set log to color console other than JSON format.
10:13PM ??? Set log level
10:13PM INF create new scaffold project force=false pluginType=py projectName=demo
10:13PM INF create folder path=demo
10:13PM INF create folder path=demo/har
10:13PM INF create file path=demo/har/.keep
10:13PM INF create folder path=demo/testcases
10:13PM INF create folder path=demo/reports
10:13PM INF create file path=demo/reports/.keep
10:13PM INF create file path=demo/.gitignore
10:13PM INF create file path=demo/.env
10:13PM INF create file path=demo/testcases/demo_with_funplugin.json
10:13PM INF create file path=demo/testcases/demo_requests.yml
10:13PM INF create file path=demo/testcases/demo_ref_testcase.yml
10:13PM INF start to create hashicorp python plugin
10:13PM INF create file path=demo/debugtalk.py
10:13PM INF ensure python3 venv packages=["funppy==v0.4.3"] python=/Users/debugtalk/.hrp/venv/bin/python
10:13PM INF python package is ready name=funppy version=0.4.3
10:13PM INF create scaffold success projectName=demo

The following is the directory structure of the project project. The testcases folder contains several sample testcases.

$ tree demo -a
demo
├── .env
├── .gitignore
├── debugtalk.py
├── har
   └── .keep
├── reports
   └── .keep
└── testcases
    ├── demo_ref_testcase.yml
    ├── demo_requests.yml
    └── demo_with_funplugin.json

3 directories, 8 files

Test case

Let’s take demo_requests.yml as an example to give an initial preview of HttpRunner’s test case structure.

config:
    name: "request methods testcase with functions"
    variables:
        foo1: config_bar1
        foo2: config_bar2
        expect_foo1: config_bar1
        expect_foo2: config_bar2
    base_url: "https://postman-echo.com"
    verify: False
    export: ["foo3"]

teststeps:
-
    name: get with params
    variables:
        foo1: bar11
        foo2: bar21
        sum_v: "${sum_two(1, 2)}"
    request:
        method: GET
        url: /get
        params:
            foo1: $foo1
            foo2: $foo2
            sum_v: $sum_v
        headers:
            User-Agent: HttpRunner/${get_httprunner_version()}
    extract:
        foo3: "body.args.foo2"
    validate:
        - eq: ["status_code", 200]
        - eq: ["body.args.foo1", "bar11"]
        - eq: ["body.args.sum_v", "3"]
        - eq: ["body.args.foo2", "bar21"]
-
    name: post raw text
    variables:
        foo1: "bar12"
        foo3: "bar32"
    request:
        method: POST
        url: /post
        headers:
            User-Agent: HttpRunner/${get_httprunner_version()}
            Content-Type: "text/plain"
        data: "This is expected to be sent back as part of response body: $foo1-$foo2-$foo3."
    validate:
        - eq: ["status_code", 200]
        - eq: ["body.data", "This is expected to be sent back as part of response body: bar12-$expect_foo2-bar32."]
-
    name: post form data
    variables:
        foo2: bar23
    request:
        method: POST
        url: /post
        headers:
            User-Agent: HttpRunner/${get_httprunner_version()}
            Content-Type: "application/x-www-form-urlencoded"
        data: "foo1=$foo1&foo2=$foo2&foo3=$foo3"
    validate:
        - eq: ["status_code", 200]
        - eq: ["body.form.foo1", "$expect_foo1"]
        - eq: ["body.form.foo2", "bar23"]
        - eq: ["body.form.foo3", "bar21"]

The HttpRunner test case has and only two parts:

  • config: specifies the common configuration of the test case, including the use case name, base_url, parameterized data source, and whether SSL verification is enabled
  • eststeps: a set of ordered steps; Adopt the go interface design concept, support for any protocol and test type extension (even including UI automation)

In the above case, each step is an HTTP request; As you can see, the description contains only the core elements of the HTTP request and result verification, without any cumbersome content.

At the same time, it is important to note that while the above use case is YAML text, it also supports referring to variables and calling functions.

  • Variable reference: The convention refers to variables in the form of ${} or $, such as $foo1 or ${foo1}
  • Function call: The convention calls plug-in functions in the form of ${}, such as ${sum_two(1, 2)}

The declaration of variables is defined in the step or config variables and follows priority requirements.

The function declaration is defined in the project root directory debugtalk.py, based on the “convention over configuration” design philosophy, we do not need to configure in the test case.

import funppy


def get_httprunner_version():
    return "v4.0.0-alpha"


def sum_two_int(a: int, b: int) -> int:
    return a + b


if __name__ == '__main__':
    funppy.register("get_httprunner_version", get_httprunner_version)
    funppy.register("sum_two", sum_two_int)
    funppy.serve()

In debugtalk.py, we can write functions that implement any custom logic, just register and serve() through funppy.

Run interface test

After the test case is ready, run the hrp run command to execute the specified test case. To generate HTML test reports, attach the –gen-html-report parameter.

$ hrp run demo/testcases/demo_requests.yml demo/testcases/demo_ref_testcase.yml --gen-html-report

The HTML report generated by the test looks like this:

ba2c29aff94545038e231e7ca19c8ce3noop.image_

Operational performance test

For existing interface test cases, HttpRunner can run the performance test through the hrp boom command without any extra work. The number of concurrent users can be specified with the –spawn-count parameter, and the start pressure slope can be specified with the –spawn-rate parameter.

$ hrp boom testcases/demo_requests.yml --spawn-count 100 --spawn-rate 10

During the operation of the pressure measurement, the disposable energy summary data is printed every 3 seconds; When the test is terminated by pressing CTRL + C, a statistical Summary of the entire pressure measurement process is printed.

—END—

Open source protocol: Apache2.0

资源下载此资源为免费资源立即下载
Telegram:@John_Software

Disclaimer: This article is published by a third party and represents the views of the author only and has nothing to do with this website. This site does not make any guarantee or commitment to the authenticity, completeness and timeliness of this article and all or part of its content, please readers for reference only, and please verify the relevant content. The publication or republication of articles by this website for the purpose of conveying more information does not mean that it endorses its views or confirms its description, nor does it mean that this website is responsible for its authenticity.

Ictcoder Free source code GO based on the development of open source API testing tools, support HTTP/WebSocket/RPC and other protocols https://ictcoder.com/kyym/an-open-source-api-testing-tool-developed-based-on-go-supporting-protocols-such-as-http-websocket-rpc-etc.html

Qizhuwang Source Code Trading Platform

Q&A
  • 1, automatic: after taking the photo, click the (download) link to download; 2. Manual: After taking the photo, contact the seller to issue it or contact the official to find the developer to ship.
View details
  • 1, the default transaction cycle of the source code: manual delivery of goods for 1-3 days, and the user payment amount will enter the platform guarantee until the completion of the transaction or 3-7 days can be issued, in case of disputes indefinitely extend the collection amount until the dispute is resolved or refunded!
View details
  • 1. Heptalon will permanently archive the process of trading between the two parties and the snapshots of the traded goods to ensure that the transaction is true, effective and safe! 2, Seven PAWS can not guarantee such as "permanent package update", "permanent technical support" and other similar transactions after the merchant commitment, please identify the buyer; 3, in the source code at the same time there is a website demonstration and picture demonstration, and the site is inconsistent with the diagram, the default according to the diagram as the dispute evaluation basis (except for special statements or agreement); 4, in the absence of "no legitimate basis for refund", the commodity written "once sold, no support for refund" and other similar statements, shall be deemed invalid; 5, before the shooting, the transaction content agreed by the two parties on QQ can also be the basis for dispute judgment (agreement and description of the conflict, the agreement shall prevail); 6, because the chat record can be used as the basis for dispute judgment, so when the two sides contact, only communicate with the other party on the QQ and mobile phone number left on the systemhere, in case the other party does not recognize self-commitment. 7, although the probability of disputes is very small, but be sure to retain such important information as chat records, mobile phone messages, etc., in case of disputes, it is convenient for seven PAWS to intervene in rapid processing.
View details
  • 1. As a third-party intermediary platform, Qichou protects the security of the transaction and the rights and interests of both buyers and sellers according to the transaction contract (commodity description, content agreed before the transaction); 2, non-platform online trading projects, any consequences have nothing to do with mutual site; No matter the seller for any reason to require offline transactions, please contact the management report.
View details

Related Article

make a comment
No comments available at the moment
Official customer service team

To solve your worries - 24 hours online professional service