当我在本地运行它时,该应用程序工作正常:$ dev_appserver.py app.yaml
但是,当我尝试运行测试时,似乎没有设置 ENV。
$ 去测试 -v
skincare.go:6:5: cannot find package "appengine" in any of:
/usr/local/go/src/appengine (from $GOROOT)
/Users/bryan/go/src/appengine (from $GOPATH)
skincare.go:7:5: cannot find package "appengine/datastore" in any of:
/usr/local/go/src/appengine/datastore (from $GOROOT)
/Users/bryan/go/src/appengine/datastore (from $GOPATH)
skincare.go:8:5: cannot find package "appengine/user" in any of:
/usr/local/go/src/appengine/user (from $GOROOT)
/Users/bryan/go/src/appengine/user (from $GOPATH)
$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/bryan/go/"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT="1"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"
$GOPATH
不应包含路径的src
部分。因此,与其指向/Users/bryan/go/src/
,不如指向/Users/bryan/go
.
我怀疑您的测试失败是因为您直接使用 go test
调用它们,而不是使用 App Engine SDK 的测试运行程序 goapp test
,它会在 appengine 包运行时将您链接到 appengine 包。