Showing posts with label test. Show all posts
Showing posts with label test. Show all posts

Thursday, January 8, 2015

TestMain in go 1.4 testing module


Provide setup and teardow to your test with g0 1.4 testing module:


 
func setUp() {

  ...
}
 
func tearDown() {
  ...
}

func TestMain(m *testing.M) {
     setUp()
     r := m.Run()
     tearDown() // cannot run tearDown in a defer because of os.Exit
  os.Exit(r)
} 

func TestFoo(t *testing.T) { 
  ...
}
 
func TestBar(t *testing.T) { 
  ...
}