我正在使用 “google.golang.org/appengine/aetest” 像这样打包和设置我的 TestMain:
var myAeInst aetest.Instance
func TestMain(m *testing.M) {
var err error
myAeInst, err = aetest.NewInstance(&aetest.Options{StronglyConsistentDatastore: true})
defer tearDown()
c := m.Run()
os.Exit(code)
}
func tearDown() {
if myAeInst != nil {
myAeInst.Close()
}
}
但是一直卡在aetest.NewInstance,有没有人遇到过类似的问题?
最佳答案
您正在调用 defer tearDown()
,然后调用 os.Exit(code)
,后者调用 tearDown
之后 os.Exit
(即从不)。您需要在 os.Exit
之前显式调用 tearDown
,或者创建一个您延迟 不 调用 的新函数os.退出
。
关于google-app-engine - 如何将 TestMain 与全局 aetest.NewInstance 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35078143/