mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-06 15:01:22 +08:00
feat: support setting global testcase timeout and step timeout
This commit is contained in:
@@ -2,6 +2,7 @@ package hrp
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
@@ -172,3 +173,58 @@ func TestRunRequestStatOn(t *testing.T) {
|
||||
t.Fatal()
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunCaseWithTimeout(t *testing.T) {
|
||||
r := NewRunner(t)
|
||||
|
||||
// global timeout
|
||||
testcase1 := &TestCase{
|
||||
Config: NewConfig("TestCase1").
|
||||
SetTimeout(2 * time.Second). // set global timeout to 2s
|
||||
SetBaseURL("http://httpbin.org"),
|
||||
TestSteps: []IStep{
|
||||
NewStep("step1").
|
||||
GET("/delay/1").
|
||||
Validate().
|
||||
AssertEqual("status_code", 200, "check status code"),
|
||||
},
|
||||
}
|
||||
err := r.Run(testcase1)
|
||||
if !assert.NoError(t, err) { // assert no error
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
testcase2 := &TestCase{
|
||||
Config: NewConfig("TestCase2").
|
||||
SetTimeout(2 * time.Second). // set global timeout to 2s
|
||||
SetBaseURL("http://httpbin.org"),
|
||||
TestSteps: []IStep{
|
||||
NewStep("step1").
|
||||
GET("/delay/3").
|
||||
Validate().
|
||||
AssertEqual("status_code", 200, "check status code"),
|
||||
},
|
||||
}
|
||||
err = r.Run(testcase2)
|
||||
if !assert.Error(t, err) { // assert error
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
// step timeout
|
||||
testcase3 := &TestCase{
|
||||
Config: NewConfig("TestCase3").
|
||||
SetTimeout(2 * time.Second).
|
||||
SetBaseURL("http://httpbin.org"),
|
||||
TestSteps: []IStep{
|
||||
NewStep("step2").
|
||||
GET("/delay/3").
|
||||
SetTimeout(4*time.Second). // set step timeout to 4s
|
||||
Validate().
|
||||
AssertEqual("status_code", 200, "check status code"),
|
||||
},
|
||||
}
|
||||
err = r.Run(testcase3)
|
||||
if !assert.NoError(t, err) {
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user