moraes
moraes

Reputation: 13629

How to run unit tests for code that uses App Engine services in Go?

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.

Upvotes: 12

Views: 1457

Answers (3)

Ezequiel Muns
Ezequiel Muns

Reputation: 7742

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

Upvotes: 6

Sudhir Jonathan
Sudhir Jonathan

Reputation: 17516

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.

Upvotes: 1

proppy
proppy

Reputation: 10504

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

Upvotes: 6

Related Questions