mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-07 00:17:37 +08:00
docs: update example
This commit is contained in:
@@ -30,7 +30,7 @@ $ go get -u github.com/httprunner/hrp
|
|||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
This is an example of `hrp` testcase. You can find more in the [`examples`][examples] directory.
|
This is an example of `HttpRunner+` testcase. You can find more in the [`examples`][examples] directory.
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -72,7 +72,7 @@ func TestCaseDemo(t *testing.T) {
|
|||||||
AssertEqual("body.args.foo2", "34.5", "check args foo2"), // notice: request params value will be converted to string
|
AssertEqual("body.args.foo2", "34.5", "check args foo2"), // notice: request params value will be converted to string
|
||||||
hrp.Step("post json data").
|
hrp.Step("post json data").
|
||||||
POST("/post").
|
POST("/post").
|
||||||
WithJSON(map[string]interface{}{
|
WithBody(map[string]interface{}{
|
||||||
"foo1": "$varFoo1", // reference former extracted variable
|
"foo1": "$varFoo1", // reference former extracted variable
|
||||||
"foo2": "${max($a, $b)}", // 12.3; step level variables are independent, variable b is 3.45 here
|
"foo2": "${max($a, $b)}", // 12.3; step level variables are independent, variable b is 3.45 here
|
||||||
}).
|
}).
|
||||||
@@ -80,6 +80,16 @@ func TestCaseDemo(t *testing.T) {
|
|||||||
AssertEqual("status_code", 200, "check status code").
|
AssertEqual("status_code", 200, "check status code").
|
||||||
AssertLengthEqual("body.json.foo1", 5, "check args foo1").
|
AssertLengthEqual("body.json.foo1", 5, "check args foo1").
|
||||||
AssertEqual("body.json.foo2", 12.3, "check args foo2"),
|
AssertEqual("body.json.foo2", 12.3, "check args foo2"),
|
||||||
|
hrp.Step("post form data").
|
||||||
|
POST("/post").
|
||||||
|
WithParams(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
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user