mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-13 17:29:56 +08:00
feat: dump TestCase to json/yaml file
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user