3

我的 appengine SDK 在 ~/Applications/google_appengine

在 Eclipse 中,我有一个外部工具设置来运行开发服务器。它指向:

~/Application/google_appengine/dev_appserver.py

同样在 Eclipse (Go Preferences) 中,我将 GOROOT 设置为指向

~/Application/google_appengine/goroot

现在,我正在尝试为我的项目运行一些单元测试。如果我使用常规的 go 安装(不是 appengine 安装的),我会收到以下错误:

../../context/context.go:4:2: cannot find package "appengine" in any of:
/usr/local/go/src/pkg/appengine (from $GOROOT)
/Users/home/src/go/foodbox/src/appengine (from $GOPATH)
../../context/data.go:4:2: cannot find package "appengine/datastore" in any of:
/usr/local/go/src/pkg/appengine/datastore (from $GOROOT)
/Users/home/src/go/foodbox/src/appengine/datastore (from $GOPATH)
../../context/context.go:5:2: cannot find package "appengine/user" in any of:
/usr/local/go/src/pkg/appengine/user (from $GOROOT)
/Users/home/src/go/foodbox/src/appengine/user (from $GOPATH)

如果我使用 appengine go,我会得到这个:

load cmd/cgo: package cmd/cgo: no Go source files in /Users/home/Application/google_appengine/goroot/src/cmd/cgo

似乎默认安装找不到 appengine 包(我想这并不奇怪)。当我使用 appengine go 工具时,我不确定问题出在哪里。谁能告诉我如何让它工作?

谢谢!

4

2 回答 2

5

值得一提的是,该appengine/aetest软件包现在包含在 SDK 中,从 1.8.6 开始。请参阅文档

基本上你会得到一个appengine.Context可以在你的测试中使用的,类似于icub3d/appenginetesting

引用文档中的示例:

import (
        "testing"

        "appengine/aetest"
)

func TestMyFunction(t *testing.T) {
        c, err := aetest.NewContext(nil)
        if err != nil {
                t.Fatal(err)
        }
        defer c.Close()

        // Run code and tests requiring the appengine.Context using c.
}
于 2013-11-04T13:19:08.653 回答
0

请参阅文档:

http://blog.golang.org/appengine-dec2013

查看名为“本地单元测试”的部分

我认为您正在寻找的是goapp testsdk 附带的。

于 2014-10-03T18:47:09.050 回答