1. 引用包 : gocheck "gopkg.in/check.v1"
2. 自动化测试入口 :Test_run(t *testing.T)
3. 将自定义的测试用例集,注册到如下suites集合中即可
代码如下:
1 import ( 2 "testing" 3 gocheck "gopkg.in/check.v1" 4 ) 5 6 var AllSuites []interface{} 7 8 9 func RunSuites(suites []interface{}, t *testing.T) { 10 for _, suite := range suites { 11 var _ = gocheck.Suite(suite) 12 AllSuites = append(AllSuites, suite) 13 } 14 gocheck.TestingT(t) 15 } 16 17 18 19 var suites = []interface{}{ 20 //add test suite 21 &domain_transfer{}, 22 } 23 24 func Test_run(t *testing.T) { 25 RunSuites(suites, t) 26 }
测试用例代码如下:
1 import ( 2 . "gopkg.in/check.v1" 3 ) 4 5 type domain_transfer struct { 6 } 7 8 func (s *domain_transfer) SetUpSuite(c *C) { 9 10 print("do some preparation here") 11 ::: 12 13 } 14 15 func (s *domain_transfer) TearDownSuite(c *C) { 16 ::: 17 } 18 19 func (s *domain_transfer) TestDomainTest(c *C,) { 20 ::: 21 assert.Equal(c,true,result) 22 23 }