mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 07:26:55 +08:00
feat: support nested testcase in teststep
This commit is contained in:
@@ -50,6 +50,7 @@ type TValidator struct {
|
|||||||
type TStep struct {
|
type TStep struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Request *TRequest `json:"request"`
|
Request *TRequest `json:"request"`
|
||||||
|
TestCase *TestCase `json:"testcase"`
|
||||||
Variables Variables `json:"variables"`
|
Variables Variables `json:"variables"`
|
||||||
SetupHooks []string `json:"setup_hooks"`
|
SetupHooks []string `json:"setup_hooks"`
|
||||||
TeardownHooks []string `json:"teardown_hooks"`
|
TeardownHooks []string `json:"teardown_hooks"`
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ func TestHttpRunner(t *testing.T) {
|
|||||||
Validate().
|
Validate().
|
||||||
AssertEqual("status_code", 200, "check status code").
|
AssertEqual("status_code", 200, "check status code").
|
||||||
AssertEqual("body.\"user-agent\"", "python-requests", "check User-Agent"),
|
AssertEqual("body.\"user-agent\"", "python-requests", "check User-Agent"),
|
||||||
|
RunTestCase("TestCase3").WithVariables(Variables{"var1": "value1"}),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
testcase2 := &TestCase{
|
testcase2 := &TestCase{
|
||||||
|
|||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
package httpboomer
|
||||||
|
|
||||||
|
func RunTestCase(name string) *TestCase {
|
||||||
|
return &TestCase{
|
||||||
|
Config: TConfig{
|
||||||
|
Name: name,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tc *TestCase) WithVariables(variables Variables) *TestCase {
|
||||||
|
tc.Config.Variables = variables
|
||||||
|
return tc
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tc *TestCase) ToStruct() *TStep {
|
||||||
|
return &TStep{
|
||||||
|
TestCase: tc,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tc *TestCase) Run() error {
|
||||||
|
for _, step := range tc.TestSteps {
|
||||||
|
if err := step.Run(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user