golang init 与 test

执行go test 也会先执行init()

init.go

package testinitimport ("fmt"
)func init(){fmt.Println("initing........")
}

hello.go

package testinitimport "fmt"func hello(){fmt.Println("!!!!!hello")
}

hello_test.go

package testinitimport ("fmt""testing"
)func TestHello(t *testing.T){fmt.Println("test begining....")hello()
}

out :

PS D:\goproject\src\first\2020-9-17\testinit> go test
initing........
test begining....
!!!!!hello
PASS
ok      first/2020-9-17/testinit        0.369s