feat: run referenced testcase

This commit is contained in:
debugtalk
2021-09-23 11:59:52 +08:00
parent edaaaee6a3
commit 9f8398a865
2 changed files with 13 additions and 4 deletions

View File

@@ -36,9 +36,18 @@ func (r *Runner) runCase(testcase *TestCase) error {
config := &testcase.Config
log.Printf("Start to run testcase: %v", config.Name)
for _, step := range testcase.TestSteps {
tStep := parseStep(step, config)
if err := r.runStep(tStep); err != nil {
return err
if tc, ok := step.(*testcaseWithOptionalArgs); ok {
// run referenced testcase
log.Printf("run referenced testcase: %v", tc.step.Name)
if err := r.runCase(tc.step.TestCase); err != nil {
return err
}
} else {
// run request
tStep := parseStep(step, config)
if err := r.runStep(tStep); err != nil {
return err
}
}
}
return nil

View File

@@ -21,7 +21,7 @@ func TestHttpRunner(t *testing.T) {
Validate().
AssertEqual("status_code", 200, "check status code").
AssertEqual("body.\"user-agent\"", "python-requests", "check User-Agent"),
Step("TestCase3").CallRefCase(&TestCase{}),
Step("TestCase3").CallRefCase(&TestCase{Config: TConfig{Name: "TestCase3"}}),
},
}
testcase2 := &TestCase{