MCPcopy
hub / github.com/httprunner/httprunner / TestRunCaseWithThinkTime

Function TestRunCaseWithThinkTime

hrp/runner_test.go:101–157  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

99}
100
101func TestRunCaseWithThinkTime(t *testing.T) {
102 buildHashicorpGoPlugin()
103 defer removeHashicorpGoPlugin()
104
105 testcases := []*TestCase{
106 {
107 Config: NewConfig("TestCase1"),
108 TestSteps: []IStep{
109 NewStep("thinkTime").SetThinkTime(2),
110 },
111 },
112 {
113 Config: NewConfig("TestCase2").
114 SetThinkTime(thinkTimeIgnore, nil, 0),
115 TestSteps: []IStep{
116 NewStep("thinkTime").SetThinkTime(0.5),
117 },
118 },
119 {
120 Config: NewConfig("TestCase3").
121 SetThinkTime(thinkTimeRandomPercentage, nil, 0),
122 TestSteps: []IStep{
123 NewStep("thinkTime").SetThinkTime(1),
124 },
125 },
126 {
127 Config: NewConfig("TestCase4").
128 SetThinkTime(thinkTimeRandomPercentage, map[string]interface{}{"min_percentage": 2, "max_percentage": 3}, 2.5),
129 TestSteps: []IStep{
130 NewStep("thinkTime").SetThinkTime(1),
131 },
132 },
133 {
134 Config: NewConfig("TestCase5"),
135 TestSteps: []IStep{
136 // think time: 3s, random pct: {"min_percentage":1, "max_percentage":1.5}, limit: 4s
137 NewStep("thinkTime").CallRefCase(&demoTestCaseWithThinkTimePath),
138 },
139 },
140 }
141 expectedMinValue := []float64{2, 0, 0.5, 2, 3}
142 expectedMaxValue := []float64{2.5, 0.5, 2, 3, 10}
143 for idx, testcase := range testcases {
144 r := NewRunner(t)
145 startTime := time.Now()
146 err := r.Run(testcase)
147 if err != nil {
148 t.Fatalf("run testcase error: %v", err)
149 }
150 duration := time.Since(startTime)
151 minValue := time.Duration(expectedMinValue[idx]*1000) * time.Millisecond
152 maxValue := time.Duration(expectedMaxValue[idx]*1000) * time.Millisecond
153 if duration < minValue || duration > maxValue {
154 t.Fatalf("failed to test think time, expect value: [%v, %v], actual value: %v", minValue, maxValue, duration)
155 }
156 }
157}
158

Callers

nothing calls this directly

Calls 8

buildHashicorpGoPluginFunction · 0.85
removeHashicorpGoPluginFunction · 0.85
NewConfigFunction · 0.85
NewStepFunction · 0.85
NewRunnerFunction · 0.85
CallRefCaseMethod · 0.80
RunMethod · 0.65
SetThinkTimeMethod · 0.45

Tested by

no test coverage detected