英文:
How to run unit tests for code that uses App Engine services in Go?
问题
我被告知,运行使用App Engine服务(如数据存储或内存缓存)的代码的单元测试的最佳解决方案是在子进程中运行开发服务器,但我不确定如何操作。有人成功运行过这种测试并可以分享解决方案吗?
Go的App Engine SDK使用Python的dev_appserver;请参考此讨论。
英文:
I was told the best solution to run unit tests for code that uses App Engine services such as datastore or memcache was to run the development server in a child process, but I'm not sure how. Anybody successfully ran this kind of test and can share a solution?
App Engine SDK for Go uses the Python dev_appserver; see this thread.
答案1
得分: 6
你应该查看Josh Marsh的Google App Engine Go测试库。
英文:
You should check out Google App Engine Go testing library by Josh Marsh.
答案2
得分: 6
一个有趣的进展是,从1.8.6版本开始,通过"appengine/aetest"
包将服务存根集成到SDK中。更多信息
英文:
An interesting development, as of 1.8.6 using service stubs has been integrated into the SDK through the "appengine/aetest"
package. More info
答案3
得分: 1
我知道提问者想要建立一个测试平台并且需要这样做,但我认为这里还有另一种值得一提的方法。
除了使用测试平台来测试GAE服务之外,Go语言的有趣特性还打开了另一种可能性:编写应用程序时只需使用你所需的接口对象(它们将是官方API的子集),并在测试时将它们模拟出来。这需要你进行某种形式的依赖注入,但这是一个非常好的想法。
一旦接口被编写,你可以使用像gomock这样的库来模拟它们。
英文:
I know the questioner wants to build a testbed and needs to do this, but I think there's another approach worth mentioning here.
Besides using a testbed for the GAE services, Go's interesting nature also opens up another possibility: write your application to just require objects that have the interfaces that you use (they'd be a subset of the official APIs) and mock them out when testing. This requires you to be doing some amount of dependency injection of some sort, but that's a really good idea anyway.
Once the interfaces the interfaces are written, you can mock them using a library like gomock.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论