跳到主要内容

intro

case生成

支持与 HAR/Postman/Swagger/Curl/JMeter 等工具对接

录制生成 HAR 文件

https://httprunner.com/docs/user-guide/gen-tests/record/

转换生成测试用例

https://httprunner.com/docs/user-guide/gen-tests/convert/

--to-json/--to-yaml/--to-gotest/--to-pytest 用于将输入转化为对应目标形态的测试用例,四个选项中最多只能指定一个

手工编写

https://httprunner.com/docs/user-guide/gen-tests/write-cases/

接口测试

hrp run

go test

package tests

import (
"testing"

"github.com/httprunner/httprunner/v4/hrp"
)

func TestCaseCallFunction(t *testing.T) {
testcase := &hrp.TestCase{
Config: hrp.NewConfig("run request with functions").
SetBaseURL("https://postman-echo.com").
WithVariables(map[string]interface{}{
"n": 5,
"a": 12.3,
"b": 3.45,
}).
SetVerifySSL(false),
TestSteps: []hrp.IStep{
hrp.NewStep("get with params").
GET("/get").
WithParams(map[string]interface{}{"foo1": "${gen_random_string($n)}", "foo2": "${max($a, $b)}", "foo3": "Foo3"}).
WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}).
Extract().
WithJmesPath("body.args.foo1", "varFoo1").
Validate().
AssertEqual("status_code", 200, "check status code").
AssertLengthEqual("body.args.foo1", 5, "check args foo1").
AssertEqual("body.args.foo2", "12.3", "check args foo2").
AssertTypeMatch("body.args.foo3", "str", "check args foo3 is type string").
AssertStringEqual("body.args.foo3", "foo3", "check args foo3 case-insensitivity").
AssertContains("body.args.foo3", "Foo", "check contains ").
AssertContainedBy("body.args.foo3", "this is Foo3 test", "check contained by"), // notice: request params value will be converted to string
hrp.NewStep("post json data with functions").
POST("/post").
WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}).
WithBody(map[string]interface{}{"foo1": "${gen_random_string($n)}", "foo2": "${max($a, $b)}"}).
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"),
},
}

err := hrp.NewRunner(t).Run(testcase)
if err != nil {
t.Fatalf("run testcase error: %v", err)
}
}

性能测试

hrp boom
  • --spawn-count
  • --spawn-rate

多机负载

支持动态调整worker节点的并发用户数,(当前策略:全部 worker 均分并发用户数)

rebalance

  • ready master 与 worker 启动后的默认状态
  • spawning 正在生成并发用户,达到最大并发用户数之前的状态
  • running 正在压测
  • stopping worker 停止压测的中间状态