mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-10 23:12:41 +08:00
feat: support set debug for runner
This commit is contained in:
@@ -17,12 +17,14 @@ func Test(t *testing.T, testcases ...*TestCase) error {
|
|||||||
func NewRunner() *Runner {
|
func NewRunner() *Runner {
|
||||||
return &Runner{
|
return &Runner{
|
||||||
t: &testing.T{},
|
t: &testing.T{},
|
||||||
|
debug: false, // default to turn off debug
|
||||||
Client: req.New(),
|
Client: req.New(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Runner struct {
|
type Runner struct {
|
||||||
t *testing.T
|
t *testing.T
|
||||||
|
debug bool
|
||||||
Client *req.Req
|
Client *req.Req
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,6 +33,11 @@ func (r *Runner) WithTestingT(t *testing.T) *Runner {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Runner) SetDebug(debug bool) *Runner {
|
||||||
|
r.debug = debug
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
func (r *Runner) Run(testcases ...*TestCase) error {
|
func (r *Runner) Run(testcases ...*TestCase) error {
|
||||||
for _, testcase := range testcases {
|
for _, testcase := range testcases {
|
||||||
if err := r.runCase(testcase); err != nil {
|
if err := r.runCase(testcase); err != nil {
|
||||||
@@ -93,7 +100,7 @@ func (r *Runner) runStepRequest(step *TStep) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// do request action
|
// do request action
|
||||||
req.Debug = true
|
req.Debug = r.debug
|
||||||
resp, err := r.Client.Do(string(step.Request.Method), step.Request.URL, v...)
|
resp, err := r.Client.Do(string(step.Request.Method), step.Request.URL, v...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -77,10 +77,10 @@ func TestRunRequestRun(t *testing.T) {
|
|||||||
config := &TConfig{
|
config := &TConfig{
|
||||||
BaseURL: "https://postman-echo.com",
|
BaseURL: "https://postman-echo.com",
|
||||||
}
|
}
|
||||||
if err := defaultRunner.WithTestingT(t).runStep(stepGET, config); err != nil {
|
if err := defaultRunner.WithTestingT(t).SetDebug(true).runStep(stepGET, config); err != nil {
|
||||||
t.Fatalf("tStep.Run() error: %s", err)
|
t.Fatalf("tStep.Run() error: %s", err)
|
||||||
}
|
}
|
||||||
if err := defaultRunner.WithTestingT(t).runStep(stepPOSTData, config); err != nil {
|
if err := defaultRunner.WithTestingT(t).SetDebug(true).runStep(stepPOSTData, config); err != nil {
|
||||||
t.Fatalf("tStepPOSTData.Run() error: %s", err)
|
t.Fatalf("tStepPOSTData.Run() error: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user