feat: dump TestCase to json/yaml file

This commit is contained in:
debugtalk
2022-09-01 23:27:14 +08:00
parent e338590010
commit 47ac7dba0b
2 changed files with 26 additions and 2 deletions

View File

@@ -35,11 +35,17 @@ func TestIOSWeixinLive(t *testing.T) {
},
}
fmt.Println(testCase)
if err := testCase.Dump2JSON("demo_weixin_live.json"); err != nil {
t.Fatal(err)
}
if err := testCase.Dump2YAML("demo_weixin_live.yaml"); err != nil {
t.Fatal(err)
}
runner := hrp.NewRunner(t)
sessionRunner, _ := runner.NewSessionRunner(testCase)
if err := sessionRunner.Start(nil); err != nil {
t.Fatal()
t.Fatal(err)
}
summary := sessionRunner.GetSummary()
fmt.Println(summary)

View File

@@ -7,11 +7,11 @@ import (
"path/filepath"
"strings"
"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
"github.com/mitchellh/mapstructure"
)
// ITestCase represents interface for testcases,
@@ -51,6 +51,24 @@ func (tc *TestCase) ToTCase() *TCase {
return tCase
}
func (tc *TestCase) Dump2JSON(targetPath string) error {
tCase := tc.ToTCase()
err := builtin.Dump2JSON(tCase, targetPath)
if err != nil {
return errors.Wrap(err, "dump testcase to json failed")
}
return nil
}
func (tc *TestCase) Dump2YAML(targetPath string) error {
tCase := tc.ToTCase()
err := builtin.Dump2YAML(tCase, targetPath)
if err != nil {
return errors.Wrap(err, "dump testcase to yaml failed")
}
return nil
}
// TestCasePath implements ITestCase interface.
type TestCasePath string