MCPcopy
hub / github.com/httprunner/httprunner / TestCaseCallFunction

Function TestCaseCallFunction

hrp/tests/function_test.go:9–49  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func TestCaseCallFunction(t *testing.T) {
10 testcase := &hrp.TestCase{
11 Config: hrp.NewConfig("run request with functions").
12 SetBaseURL("https://postman-echo.com").
13 WithVariables(map[string]interface{}{
14 "n": 5,
15 "a": 12.3,
16 "b": 3.45,
17 }).
18 SetVerifySSL(false),
19 TestSteps: []hrp.IStep{
20 hrp.NewStep("get with params").
21 GET("/get").
22 WithParams(map[string]interface{}{"foo1": "${gen_random_string($n)}", "foo2": "${max($a, $b)}", "foo3": "Foo3"}).
23 WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}).
24 Extract().
25 WithJmesPath("body.args.foo1", "varFoo1").
26 Validate().
27 AssertEqual("status_code", 200, "check status code").
28 AssertLengthEqual("body.args.foo1", 5, "check args foo1").
29 AssertEqual("body.args.foo2", "12.3", "check args foo2").
30 AssertTypeMatch("body.args.foo3", "str", "check args foo3 is type string").
31 AssertEqualFold("body.args.foo3", "foo3", "check args foo3 case-insensitivity").
32 AssertContains("body.args.foo3", "Foo", "check contains ").
33 AssertContainedBy("body.args.foo3", "this is Foo3 test", "check contained by"), // notice: request params value will be converted to string
34 hrp.NewStep("post json data with functions").
35 POST("/post").
36 WithHeaders(map[string]string{"User-Agent": "HttpRunnerPlus"}).
37 WithBody(map[string]interface{}{"foo1": "${gen_random_string($n)}", "foo2": "${max($a, $b)}"}).
38 Validate().
39 AssertEqual("status_code", 200, "check status code").
40 AssertLengthEqual("body.json.foo1", 5, "check args foo1").
41 AssertEqual("body.json.foo2", 12.3, "check args foo2"),
42 },
43 }
44
45 err := hrp.NewRunner(t).Run(testcase)
46 if err != nil {
47 t.Fatalf("run testcase error: %v", err)
48 }
49}

Callers

nothing calls this directly

Calls 15

NewConfigFunction · 0.92
NewStepFunction · 0.92
NewRunnerFunction · 0.92
SetVerifySSLMethod · 0.80
SetBaseURLMethod · 0.80
AssertContainedByMethod · 0.80
AssertContainsMethod · 0.80
AssertEqualFoldMethod · 0.80
AssertTypeMatchMethod · 0.80
AssertEqualMethod · 0.80
AssertLengthEqualMethod · 0.80
WithJmesPathMethod · 0.80

Tested by

no test coverage detected