mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-08 00:47:36 +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)
|
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)
|
runner := hrp.NewRunner(t)
|
||||||
sessionRunner, _ := runner.NewSessionRunner(testCase)
|
sessionRunner, _ := runner.NewSessionRunner(testCase)
|
||||||
if err := sessionRunner.Start(nil); err != nil {
|
if err := sessionRunner.Start(nil); err != nil {
|
||||||
t.Fatal()
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
summary := sessionRunner.GetSummary()
|
summary := sessionRunner.GetSummary()
|
||||||
fmt.Println(summary)
|
fmt.Println(summary)
|
||||||
|
|||||||
+19
-1
@@ -7,11 +7,11 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/mitchellh/mapstructure"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
|
||||||
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
||||||
"github.com/mitchellh/mapstructure"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ITestCase represents interface for testcases,
|
// ITestCase represents interface for testcases,
|
||||||
@@ -51,6 +51,24 @@ func (tc *TestCase) ToTCase() *TCase {
|
|||||||
return 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.
|
// TestCasePath implements ITestCase interface.
|
||||||
type TestCasePath string
|
type TestCasePath string
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user