我有以下的TestMain函数:
以下是样例测试。
函数TestSomeFeature确实运行了,但是说dbInstance未定义。为什么它无法访问该变量?从我看到的示例中,使用此语法访问在TestMain中设置的变量。
func TestMain(m *testing.M) {
db := "[working_db_connection]"
dbInstance, _ := InitializeRepo(db, 2)
runTests := m.Run()
os.Exit(runTests)
}
以下是样例测试。
func TestSomeFeature(t *testing.T) {
fmt.Println(dbInstance)
}
函数TestSomeFeature确实运行了,但是说dbInstance未定义。为什么它无法访问该变量?从我看到的示例中,使用此语法访问在TestMain中设置的变量。
DbInstance
是否会作为包的一部分被导出? - kovac