सादा गोलांग 1.7 के साथ Convey और Ginkgo जैसे तृतीय पक्ष पुस्तकालयों के अलावा, आप अनुक्रमिक रूप से परीक्षण चला सकते हैं। आप और अधिक here
func TestFoo(t *testing.T) {
// <setup code>
t.Run("A=1", func(t *testing.T) { ... })
t.Run("A=2", func(t *testing.T) { ... })
t.Run("B=1", func(t *testing.T) { ... })
// <tear-down code>
}
पढ़ सकते हैं और आप उन लोगों के साथ सशर्त चला सकते हैं:
go test -run '' # Run all tests.
go test -run Foo # Run top-level tests matching "Foo", such as "TestFooBar".
go test -run Foo/A= # For top-level tests matching "Foo", run subtests matching "A=".
go test -run /A=1 # For all top-level tests, run subtests matching "A=1".
तो कहते हैं कि तुम एक REST API आप परीक्षण करना चाहते हैं से एक user
पैकेज मिला देता है। लॉगिन हैंडलर का परीक्षण करने में सक्षम होने के लिए आपको बनाने हैंडलर का परीक्षण करने की आवश्यकता है। आम तौर पर मैं user_test.go
type UserTests struct { Test *testing.T}
func TestRunner(t *testing.T) {
t.Run("A=create", func(t *testing.T) {
test:= UserTests{Test: t}
test.TestCreateRegularUser()
test.TestCreateConfirmedUser()
test.TestCreateMasterUser()
test.TestCreateUserTwice()
})
t.Run("A=login", func(t *testing.T) {
test:= UserTests{Test: t}
test.TestLoginRegularUser()
test.TestLoginConfirmedUser()
test.TestLoginMasterUser()
})
}
पर इस के लिए होता है तो मैं UserTest प्रकार है कि अभ्यस्त किसी भी _test.go
फ़ाइल में go test
आदेश द्वारा निष्पादित की जाने तरीकों जोड़ सकते हैं
func (t *UserTests) TestCreateRegularUser() {
registerRegularUser := util.TableTest{
Method: "POST",
Path: "/iot/users",
Status: http.StatusOK,
Name: "registerRegularUser",
Description: "register Regular User has to return 200",
Body: SerializeUser(RegularUser),
}
response := util.SpinSingleTableTests(t.Test, registerRegularUser)
util.LogIfVerbose(color.BgCyan, "IOT/USERS/TEST", response)
}
आप पुष्टि कर सकते हैं कि आदेश वास्तव में है इस तरह के परीक्षणों को समूहीकृत करके नियंत्रित किया जाता है? दस्तावेज़ कहते हैं कि आप paralellism को नियंत्रित कर सकते हैं, लेकिन यह नहीं कि वे क्रमशः उस क्रम में भाग लेंगे जिसे 'टी' कहा जाता है। रेस की स्थिति को सत्यापित करना बहुत मुश्किल है ... अगर मुझे कोई निश्चित सबूत मिल जाए तो मैं वापस जवाब दूंगा। – threeve
@ थ्रीव वे निश्चित रूप से निश्चित रूप से चलते हैं। आप मूल रूप से इस तरह एक एकल परीक्षण चला रहे हैं। – CESCO