How to run unit tests for code that uses App Engin

2019-04-19 16:17发布

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.

3条回答
Root(大扎)
2楼-- · 2019-04-19 16:48

You should check out Google App Engine Go testing library by Josh Marsh.

查看更多
小情绪 Triste *
3楼-- · 2019-04-19 16:48

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.

查看更多
Juvenile、少年°
4楼-- · 2019-04-19 17:02

An interesting development, as of 1.8.6 using service stubs has been integrated into the SDK through the "appengine/aetest" package. More info

查看更多
登录 后发表回答