mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-07 07:21:23 +08:00
refactor: merge hrp into httprunner repo
This commit is contained in:
316
hrp/README.md
316
hrp/README.md
@@ -1,316 +0,0 @@
|
||||
# hrp (HttpRunner+)
|
||||
|
||||
[](https://pkg.go.dev/github.com/httprunner/hrp)
|
||||
[](https://github.com/httprunner/hrp/actions)
|
||||
[](https://codecov.io/gh/httprunner/hrp)
|
||||
[](https://goreportcard.com/report/github.com/httprunner/hrp)
|
||||
[](https://app.fossa.com/reports/c2742455-c8ab-4b13-8fd7-4a35ba0b2840)
|
||||
|
||||
`hrp` aims to be a one-stop solution for HTTP(S) testing, covering API testing, load testing and digital experience monitoring (DEM).
|
||||
|
||||
See [CHANGELOG].
|
||||
|
||||
> HttpRunner [用户调研问卷][survey] 持续收集中,我们将基于用户反馈动态调整产品特性和需求优先级。
|
||||
|
||||
## Key Features
|
||||
|
||||

|
||||
|
||||
### API Testing
|
||||
|
||||
- [x] Full support for HTTP(S)/1.1 requests.
|
||||
- [ ] Support more protocols, HTTP/2, WebSocket, TCP, RPC etc.
|
||||
- [x] Testcases can be described in multiple formats, `YAML`/`JSON`/`Golang`, and they are interchangeable.
|
||||
- [x] Use Charles/Fiddler/Chrome/etc to record HTTP requests and generate testcases from exported [`HAR`][HAR].
|
||||
- [x] Supports `variables`/`extract`/`validate`/`hooks` mechanisms to create extremely complex test scenarios.
|
||||
- [x] Data driven with `parameterize` mechanism, supporting sequential/random/unique strategies to select data.
|
||||
- [ ] Built-in 100+ commonly used functions for ease, including md5sum, max/min, sleep, gen_random_string etc.
|
||||
- [x] Create and call custom functions with `plugin` mechanism, support [hashicorp plugin] and [go plugin].
|
||||
- [x] Generate html reports with rich test results.
|
||||
- [x] Using it as a `CLI tool` or a `library` are both supported.
|
||||
|
||||
### Load Testing
|
||||
|
||||
Base on the API testing testcases, you can run professional load testing without extra work.
|
||||
|
||||
- [x] Inherit all powerful features of [`locust`][locust] and [`boomer`][boomer].
|
||||
- [x] Report performance metrics to [prometheus pushgateway][pushgateway].
|
||||
- [x] Use `transaction` to define a set of end-user actions that represent the real user activities.
|
||||
- [x] Use `rendezvous` points to force Vusers to perform tasks concurrently during test execution.
|
||||
- [x] Load testing with specified concurrent users or constant RPS, also supports spawn rate.
|
||||
- [ ] Support mixed-scenario testing with custom weight.
|
||||
- [ ] Simulate browser's HTTP parallel connections.
|
||||
- [ ] IP spoofing.
|
||||
- [ ] Run in distributed mode to generate unlimited RPS.
|
||||
|
||||
### Digital Experience Monitoring (DEM)
|
||||
|
||||
You can also monitor online services for digital experience assessments.
|
||||
|
||||
- [ ] HTTP(S) latency statistics including DNSLookup, TCP connections, SSL handshakes, content transfers, etc.
|
||||
- [ ] `ping` indicators including latency, throughput and packets loss.
|
||||
- [ ] traceroute
|
||||
- [ ] DNS monitoring
|
||||
|
||||
## Quick Start
|
||||
|
||||
### use as CLI tool
|
||||
|
||||
You can install `hrp` with one shell command, which will download the latest version's released binary and install to the current system.
|
||||
|
||||
```bash
|
||||
# install via curl
|
||||
$ bash -c "$(curl -ksSL https://httprunner.oss-cn-beijing.aliyuncs.com/install.sh)"
|
||||
# install via wget
|
||||
$ bash -c "$(wget https://httprunner.oss-cn-beijing.aliyuncs.com/install.sh -O -)"
|
||||
```
|
||||
|
||||
If you are a golang developer, you can also install `hrp` with `go get`.
|
||||
|
||||
```bash
|
||||
$ go get github.com/httprunner/hrp/cli/hrp
|
||||
```
|
||||
|
||||
Since installed, you will get a `hrp` command with multiple sub-commands.
|
||||
|
||||
```text
|
||||
$ hrp -h
|
||||
|
||||
██╗ ██╗████████╗████████╗██████╗ ██████╗ ██╗ ██╗███╗ ██╗███╗ ██╗███████╗██████╗
|
||||
██║ ██║╚══██╔══╝╚══██╔══╝██╔══██╗██╔══██╗██║ ██║████╗ ██║████╗ ██║██╔════╝██╔══██╗
|
||||
███████║ ██║ ██║ ██████╔╝██████╔╝██║ ██║██╔██╗ ██║██╔██╗ ██║█████╗ ██████╔╝
|
||||
██╔══██║ ██║ ██║ ██╔═══╝ ██╔══██╗██║ ██║██║╚██╗██║██║╚██╗██║██╔══╝ ██╔══██╗
|
||||
██║ ██║ ██║ ██║ ██║ ██║ ██║╚██████╔╝██║ ╚████║██║ ╚████║███████╗██║ ██║
|
||||
╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝
|
||||
|
||||
hrp (HttpRunner+) aims to be a one-stop solution for HTTP(S) testing, covering API testing,
|
||||
load testing and digital experience monitoring (DEM). Enjoy! ✨ 🚀 ✨
|
||||
|
||||
License: Apache-2.0
|
||||
Website: https://httprunner.com
|
||||
Github: https://github.com/httprunner/hrp
|
||||
Copyright 2021 debugtalk
|
||||
|
||||
Usage:
|
||||
hrp [command]
|
||||
|
||||
Available Commands:
|
||||
boom run load test with boomer
|
||||
completion generate the autocompletion script for the specified shell
|
||||
har2case convert HAR to json/yaml testcase files
|
||||
help Help about any command
|
||||
run run API test
|
||||
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.
|
||||
```
|
||||
|
||||
You can use `hrp run` command to run HttpRunner JSON/YAML testcases. The following is an example running [examples/demo.json][demo.json]
|
||||
|
||||
<details>
|
||||
<summary>$ hrp run examples/demo.json</summary>
|
||||
|
||||
```text
|
||||
5:21PM INF Set log to color console other than JSON format.
|
||||
5:21PM ??? Set log level
|
||||
5:21PM INF [init] SetDebug debug=true
|
||||
5:21PM INF [init] SetFailfast failfast=true
|
||||
5:21PM INF [init] Reset session variables
|
||||
5:21PM INF load json testcase path=/Users/debugtalk/MyProjects/HttpRunner-dev/hrp/examples/demo.json
|
||||
5:21PM INF call function success arguments=[5] funcName=gen_random_string output=A65rg
|
||||
5:21PM INF call function success arguments=[12.3,3.45] funcName=max output=12.3
|
||||
5:21PM INF run testcase start testcase="demo with complex mechanisms"
|
||||
5:21PM INF transaction name=tran1 type=start
|
||||
5:21PM INF run step start step="get with params"
|
||||
5:21PM INF call function success arguments=[12.3,34.5] funcName=max output=34.5
|
||||
-------------------- request --------------------
|
||||
GET /get?foo1=A65rg&foo2=34.5 HTTP/1.1
|
||||
Host: postman-echo.com
|
||||
User-Agent: HttpRunnerPlus
|
||||
|
||||
|
||||
==================== response ===================
|
||||
HTTP/1.1 200 OK
|
||||
Content-Length: 304
|
||||
Connection: keep-alive
|
||||
Content-Type: application/json; charset=utf-8
|
||||
Date: Thu, 23 Dec 2021 09:21:30 GMT
|
||||
Etag: W/"130-t7qE4M7C+OQ0jGdRWkr2R3gjq+w"
|
||||
Set-Cookie: sails.sid=s%3AAiqfRgMtWKG3oOQnXJOxRD8xk58rtAW6.eD%2BBo7FBnA82XLsLFiadeg6OcuD2zHSTyhv2l%2FDVuCk; Path=/; HttpOnly
|
||||
Vary: Accept-Encoding
|
||||
|
||||
{"args":{"foo1":"A65rg","foo2":"34.5"},"headers":{"x-forwarded-proto":"https","x-forwarded-port":"443","host":"postman-echo.com","x-amzn-trace-id":"Root=1-61c43f9a-7c855775053963a4284ba464","user-agent":"HttpRunnerPlus","accept-encoding":"gzip"},"url":"https://postman-echo.com/get?foo1=A65rg&foo2=34.5"}
|
||||
--------------------------------------------------
|
||||
5:21PM INF extract value from=body.args.foo1 value=A65rg
|
||||
5:21PM INF set variable value=A65rg variable=varFoo1
|
||||
5:21PM INF validate status_code assertMethod=equals checkValue=200 expectValue=200 result=true
|
||||
5:21PM INF validate headers."Content-Type" assertMethod=startswith checkValue="application/json; charset=utf-8" expectValue=application/json result=true
|
||||
5:21PM INF validate body.args.foo1 assertMethod=length_equals checkValue=A65rg expectValue=5 result=true
|
||||
5:21PM INF validate $varFoo1 assertMethod=length_equals checkValue=A65rg expectValue=5 result=true
|
||||
5:21PM INF validate body.args.foo2 assertMethod=equals checkValue=34.5 expectValue=34.5 result=true
|
||||
5:21PM INF run step end exportVars={"varFoo1":"A65rg"} step="get with params" success=true
|
||||
5:21PM INF transaction name=tran1 type=end
|
||||
5:21PM INF transaction elapsed=1021.174113 name=tran1
|
||||
5:21PM INF run step start step="post json data"
|
||||
5:21PM INF call function success arguments=[12.3,3.45] funcName=max output=12.3
|
||||
-------------------- request --------------------
|
||||
POST /post HTTP/1.1
|
||||
Host: postman-echo.com
|
||||
Content-Type: application/json; charset=UTF-8
|
||||
|
||||
{"foo1":"A65rg","foo2":12.3}
|
||||
==================== response ===================
|
||||
HTTP/1.1 200 OK
|
||||
Content-Length: 424
|
||||
Connection: keep-alive
|
||||
Content-Type: application/json; charset=utf-8
|
||||
Date: Thu, 23 Dec 2021 09:21:30 GMT
|
||||
Etag: W/"1a8-IhWXQxTXlxmnbqdRh+oBPRTLsOU"
|
||||
Set-Cookie: sails.sid=s%3AzXIPVMKipoISZG0Zj4tX73vKDbIdFtzZ.xD50I4UMHUERmcgWfp64f0a8g%2BT9YIUf0Fi1l5bXbQA; Path=/; HttpOnly
|
||||
Vary: Accept-Encoding
|
||||
|
||||
{"args":{},"data":{"foo1":"A65rg","foo2":12.3},"files":{},"form":{},"headers":{"x-forwarded-proto":"https","x-forwarded-port":"443","host":"postman-echo.com","x-amzn-trace-id":"Root=1-61c43f9a-78aab84a36a753ea6b5dd0f7","content-length":"28","user-agent":"Go-http-client/1.1","content-type":"application/json; charset=UTF-8","accept-encoding":"gzip"},"json":{"foo1":"A65rg","foo2":12.3},"url":"https://postman-echo.com/post"}
|
||||
--------------------------------------------------
|
||||
5:21PM INF validate status_code assertMethod=equals checkValue=200 expectValue=200 result=true
|
||||
5:21PM INF validate body.json.foo1 assertMethod=length_equals checkValue=A65rg expectValue=5 result=true
|
||||
5:21PM INF validate body.json.foo2 assertMethod=equals checkValue=12.3 expectValue=12.3 result=true
|
||||
5:21PM INF run step end exportVars=null step="post json data" success=true
|
||||
5:21PM INF run step start step="post form data"
|
||||
5:21PM INF call function success arguments=[12.3,3.45] funcName=max output=12.3
|
||||
-------------------- request --------------------
|
||||
POST /post HTTP/1.1
|
||||
Host: postman-echo.com
|
||||
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
|
||||
|
||||
foo1=A65rg&foo2=12.3
|
||||
==================== response ===================
|
||||
HTTP/1.1 200 OK
|
||||
Content-Length: 445
|
||||
Connection: keep-alive
|
||||
Content-Type: application/json; charset=utf-8
|
||||
Date: Thu, 23 Dec 2021 09:21:30 GMT
|
||||
Etag: W/"1bd-g4G7WmMU7EzJYzPTYgqX67Ug9iE"
|
||||
Set-Cookie: sails.sid=s%3Al3gcdxEQug7ddxPlA2Kfxvm7d_z9ImEt.4IQI1SVX5xuTefX0N0UvJPQxVvA1SAMm7ztHESkHXsY; Path=/; HttpOnly
|
||||
Vary: Accept-Encoding
|
||||
|
||||
{"args":{},"data":"","files":{},"form":{"foo1":"A65rg","foo2":"12.3"},"headers":{"x-forwarded-proto":"https","x-forwarded-port":"443","host":"postman-echo.com","x-amzn-trace-id":"Root=1-61c43f9a-6458626c64b04fd60245714b","content-length":"20","user-agent":"Go-http-client/1.1","content-type":"application/x-www-form-urlencoded; charset=UTF-8","accept-encoding":"gzip"},"json":{"foo1":"A65rg","foo2":"12.3"},"url":"https://postman-echo.com/post"}
|
||||
--------------------------------------------------
|
||||
5:21PM INF validate status_code assertMethod=equals checkValue=200 expectValue=200 result=true
|
||||
5:21PM INF validate body.form.foo1 assertMethod=length_equals checkValue=A65rg expectValue=5 result=true
|
||||
5:21PM INF validate body.form.foo2 assertMethod=equals checkValue=12.3 expectValue=12.3 result=true
|
||||
5:21PM INF run step end exportVars=null step="post form data" success=true
|
||||
5:21PM INF run testcase end testcase="demo with complex mechanisms"
|
||||
```
|
||||
</details>
|
||||
|
||||
### use as library
|
||||
|
||||
Beside using `hrp` as a CLI tool, you can also use it as golang library.
|
||||
|
||||
```bash
|
||||
$ go get -u github.com/httprunner/hrp
|
||||
```
|
||||
|
||||
This is an example of `HttpRunner+` testcase. You can find more in the [`examples`][examples] directory.
|
||||
|
||||
|
||||
<details>
|
||||
<summary>demo</summary>
|
||||
|
||||
```go
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/httprunner/hrp"
|
||||
)
|
||||
|
||||
func TestCaseDemo(t *testing.T) {
|
||||
demoTestCase := &hrp.TestCase{
|
||||
Config: hrp.NewConfig("demo with complex mechanisms").
|
||||
SetBaseURL("https://postman-echo.com").
|
||||
WithVariables(map[string]interface{}{ // global level variables
|
||||
"n": 5,
|
||||
"a": 12.3,
|
||||
"b": 3.45,
|
||||
"varFoo1": "${gen_random_string($n)}",
|
||||
"varFoo2": "${max($a, $b)}", // 12.3; eval with built-in function
|
||||
}),
|
||||
TestSteps: []hrp.IStep{
|
||||
hrp.NewStep("transaction 1 start").StartTransaction("tran1"), // start transaction
|
||||
hrp.NewStep("get with params").
|
||||
WithVariables(map[string]interface{}{ // step level variables
|
||||
"n": 3, // inherit config level variables if not set in step level, a/varFoo1
|
||||
"b": 34.5, // override config level variable if existed, n/b/varFoo2
|
||||
"varFoo2": "${max($a, $b)}", // 34.5; override variable b and eval again
|
||||
}).
|
||||
GET("/get").
|
||||
WithParams(map[string]interface{}{"foo1": "$varFoo1", "foo2": "$varFoo2"}). // request with params
|
||||
WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}). // request with headers
|
||||
Extract().
|
||||
WithJmesPath("body.args.foo1", "varFoo1"). // extract variable with jmespath
|
||||
Validate().
|
||||
AssertEqual("status_code", 200, "check response status code"). // validate response status code
|
||||
AssertStartsWith("headers.\"Content-Type\"", "application/json", ""). // validate response header
|
||||
AssertLengthEqual("body.args.foo1", 5, "check args foo1"). // validate response body with jmespath
|
||||
AssertLengthEqual("$varFoo1", 5, "check args foo1"). // assert with extracted variable from current step
|
||||
AssertEqual("body.args.foo2", "34.5", "check args foo2"), // notice: request params value will be converted to string
|
||||
hrp.NewStep("transaction 1 end").EndTransaction("tran1"), // end transaction
|
||||
hrp.NewStep("post json data").
|
||||
POST("/post").
|
||||
WithBody(map[string]interface{}{
|
||||
"foo1": "$varFoo1", // reference former extracted variable
|
||||
"foo2": "${max($a, $b)}", // 12.3; step level variables are independent, variable b is 3.45 here
|
||||
}).
|
||||
Validate().
|
||||
AssertEqual("status_code", 200, "check status code").
|
||||
AssertLengthEqual("body.json.foo1", 5, "check args foo1").
|
||||
AssertEqual("body.json.foo2", 12.3, "check args foo2"),
|
||||
hrp.NewStep("post form data").
|
||||
POST("/post").
|
||||
WithHeaders(map[string]string{"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}).
|
||||
WithBody(map[string]interface{}{
|
||||
"foo1": "$varFoo1", // reference former extracted variable
|
||||
"foo2": "${max($a, $b)}", // 12.3; step level variables are independent, variable b is 3.45 here
|
||||
}).
|
||||
Validate().
|
||||
AssertEqual("status_code", 200, "check status code").
|
||||
AssertLengthEqual("body.form.foo1", 5, "check args foo1").
|
||||
AssertEqual("body.form.foo2", "12.3", "check args foo2"), // form data will be converted to string
|
||||
},
|
||||
}
|
||||
|
||||
err := hrp.NewRunner(nil).Run(demoTestCase) // hrp.Run(demoTestCase)
|
||||
if err != nil {
|
||||
t.Fatalf("run testcase error: %v", err)
|
||||
}
|
||||
}
|
||||
```
|
||||
</details>
|
||||
|
||||
## Subscribe
|
||||
|
||||
关注 HttpRunner 的微信公众号,第一时间获得最新资讯。
|
||||
|
||||
<img src="docs/assets/qrcode.jpg" alt="HttpRunner" width="200">
|
||||
|
||||
如果你期望加入 HttpRunner 核心用户群,请填写[用户调研问卷][survey]并留下你的联系方式,作者将拉你进群。
|
||||
|
||||
[HttpRunner]: https://github.com/httprunner/httprunner
|
||||
[boomer]: https://github.com/myzhan/boomer
|
||||
[locust]: https://github.com/locustio/locust
|
||||
[jmespath]: https://jmespath.org/
|
||||
[allure]: https://docs.qameta.io/allure/
|
||||
[HAR]: http://httparchive.org/
|
||||
[hashicorp plugin]: https://github.com/hashicorp/go-plugin
|
||||
[go plugin]: https://pkg.go.dev/plugin
|
||||
[demo.json]: https://github.com/httprunner/hrp/blob/main/examples/demo.json
|
||||
[examples]: https://github.com/httprunner/hrp/blob/main/examples/
|
||||
[CHANGELOG]: docs/CHANGELOG.md
|
||||
[pushgateway]: https://github.com/prometheus/pushgateway
|
||||
[survey]: https://wj.qq.com/s2/9699514/0d19/
|
||||
9
hrp/cmd/cli/main.go
Normal file
9
hrp/cmd/cli/main.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/httprunner/httprunner/hrp/cmd"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cmd.Execute()
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
# Links
|
||||
|
||||
- Homepage: https://httprunner.com
|
||||
- Docs
|
||||
- Repo: https://github.com/httprunner/httprunner.github.io
|
||||
- 中文: https://httprunner.com/docs
|
||||
- English: https://httprunner.com/en/docs
|
||||
- [hrp command help](cmd/hrp.md)
|
||||
- Blog: https://httprunner.com/blog
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 214 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 75 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 8.5 KiB |
@@ -1 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 717.11 249.68"><title>sentry-logo-black</title><path d="M430.56,143.76,386.07,86.33H375v77h11.22v-59l45.74,59h9.82v-77H430.56Zm-112-14.27H358.4v-10H318.52V96.31h45v-10H307.07v77h57v-10H318.52Zm-46.84-9.78c-15.57-3.72-19.83-6.69-19.83-13.84,0-6.46,5.71-10.81,14.22-10.81,7.09,0,14.07,2.51,21.3,7.67l6.06-8.54c-8-6.13-16.65-9-27.13-9-15.25,0-25.89,9-25.89,21.92,0,13.84,9,18.63,25.5,22.63,14.51,3.35,18.93,6.5,18.93,13.5s-6,11.38-15.35,11.38c-9.07,0-16.81-3-25-9.82l-6.79,8.08a47.82,47.82,0,0,0,31.41,11.6c16.49,0,27.14-8.87,27.14-22.6C296.27,130.23,289.38,124,271.68,119.71Zm373.9-33.37-23.19,36.31-23-36.31H586l30.51,46.54v30.47h11.56V132.53l30.5-46.19ZM450.87,96.76H476.1v66.58h11.57V96.76h25.23V86.33h-62ZM566.4,133.28c11.64-3.21,18-11.37,18-23,0-14.78-10.84-24-28.28-24H522v77h11.45V135.62h19.42l19.54,27.72h13.37l-21.1-29.58Zm-33-7.52V96.53H555c11.27,0,17.74,5.31,17.74,14.56,0,8.91-6.92,14.67-17.62,14.67ZM144.9,65.43a13.75,13.75,0,0,0-23.81,0l-19.6,33.95,5,2.87a96.14,96.14,0,0,1,47.83,77.4H140.56a82.4,82.4,0,0,0-41-65.54l-5-2.86L76.3,143l5,2.87a46.35,46.35,0,0,1,22.46,33.78H72.33a2.27,2.27,0,0,1-2-3.41l8.76-15.17a31.87,31.87,0,0,0-10-5.71L60.42,170.5a13.75,13.75,0,0,0,11.91,20.62h43.25v-5.73A57.16,57.16,0,0,0,91.84,139l6.88-11.92a70.93,70.93,0,0,1,30.56,58.26v5.74h36.65v-5.73A107.62,107.62,0,0,0,117.09,95.3L131,71.17a2.27,2.27,0,0,1,3.93,0l60.66,105.07a2.27,2.27,0,0,1-2,3.41H179.4c.18,3.83.2,7.66,0,11.48h14.24a13.75,13.75,0,0,0,11.91-20.62Z" style="fill:#221f20"/></svg>
|
||||
|
Before Width: | Height: | Size: 1.5 KiB |
@@ -1,53 +0,0 @@
|
||||
# Builtin
|
||||
|
||||
## Builtin assertions
|
||||
|
||||
HttpRunner+ validation should follow the following format. `check`, `assert` and `expect` are required field.
|
||||
|
||||
```json
|
||||
{
|
||||
"check": "status_code", // target field, usually used with jmespath
|
||||
"assert": "equals", // assertion method, you can use builtin method or custom defined function
|
||||
"expect": 200, // expected value
|
||||
"msg": "check response status code" // optional, print this message if assertion failed
|
||||
}
|
||||
```
|
||||
|
||||
The `assert` method name will be mapped to a built-in function with the following function signature.
|
||||
|
||||
```go
|
||||
func(t assert.TestingT, actual interface{}, expected interface{}, msgAndArgs ...interface{}) bool
|
||||
```
|
||||
|
||||
Currently, HttpRunner+ has the following built-in assertion functions.
|
||||
|
||||
| `assert` | Description | A(check), B(expect) | examples |
|
||||
| --- | --- | --- | --- |
|
||||
| `eq`, `equals`, `equal` | value is equal | A == B | 9 eq 9 |
|
||||
| `lt`, `less_than` | less than | A < B | 7 lt 8 |
|
||||
| `le`, `less_or_equals` | less than or equals | A <= B | 7 le 8, 8 le 8 |
|
||||
| `gt`, `greater_than` | greater than | A > B | 8 gt 7 |
|
||||
| `ge`, `greater_or_equals` | greater than or equals | A >= B | 8 ge 7, 8 ge 8 |
|
||||
| `ne`, `not_equal` | not equals | A != B | 6 ne 9 |
|
||||
| `str_eq`, `string_equals` | string equals | str(A) == str(B) | 123 str_eq '123' |
|
||||
| `len_eq`, `length_equals`, `length_equal` | length equals | len(A) == B | 'abc' len_eq 3, [1,2] len_eq 2 |
|
||||
| `len_gt`, `count_gt`, `length_greater_than` | length greater than | len(A) > B | 'abc' len_gt 2, [1,2,3] len_gt 2 |
|
||||
| `len_ge`, `count_ge`, `length_greater_or_equals` | length greater than or equals | len(A) >= B | 'abc' len_ge 3, [1,2,3] len_gt 3 |
|
||||
| `len_lt`, `count_lt`, `length_less_than` | length less than | len(A) < B | 'abc' len_lt 4, [1,2,3] len_lt 4 |
|
||||
| `len_le`, `count_le`, `length_less_or_equals` | length less than or equals | len(A) <= B | 'abc' len_le 3, [1,2,3] len_le 3 |
|
||||
| `contains` | contains | [1, 2] contains 1 | 'abc' contains 'a', [1,2,3] len_lt 4 |
|
||||
| `contained_by` | contained by | A in B | 'a' contained_by 'abc', 1 contained_by [1,2] |
|
||||
| `type_match` | A and B are in the same type | type(A) == type(B) | 123 type_match 1 |
|
||||
| `regex_match` | regex matches | re.match(B, A) | 'abcdef' regex_match 'a\w+d' |
|
||||
| `startswith` | starts with | A.startswith(B) is True | 'abc' startswith 'ab' |
|
||||
| `endswith` | ends with | A.endswith(B) is True | 'abc' endswith 'bc' |
|
||||
|
||||
## Builtin functions
|
||||
|
||||
| Name | Arguments | Description |
|
||||
| --- | --- | --- |
|
||||
| `get_timestamp` | () | get the thirteen-digit timestamp of current time. |
|
||||
| `sleep` | (n int) | sleep n seconds to simulate the thinking time. |
|
||||
| `gen_random_string` | (n int) | get the n-digit random string. |
|
||||
| `max` | (m,n int) | get the maximum of two numbers m and n. |
|
||||
| `md5` | (s string) | get the MD5 of the input string s. |
|
||||
Reference in New Issue
Block a user