Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 760
moraes Avatar asked Oct 22 '11 09:10

moraes


People also ask

How do you unit test a mobile app?

Android unit testing For Android, unit tests are compiled to run on the Java Virtual Machine (JVM) to minimize execution time. If your tests depend on objects in the Android framework, you can use Robolectric. For tests that depend on your own dependencies, use mock objects to emulate your dependencies' behavior.

How do you test concurrency in go?

If you want to test concurrency you'll need to make a few go routines and have them run, well, concurrently. You might try taking the locking out and intentionally get it to crash or misbehave by concurrently modifying things and then add the locking in to ensure it solves it.

How do I test a go file?

At the command line in the greetings directory, run the go test command to execute the test. The go test command executes test functions (whose names begin with Test ) in test files (whose names end with _test.go). You can add the -v flag to get verbose output that lists all of the tests and their results.


3 Answers

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

like image 182
proppy Avatar answered Sep 28 '22 03:09

proppy


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

like image 45
Ezequiel Muns Avatar answered Sep 28 '22 04:09

Ezequiel Muns


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.

like image 31
Sudhir Jonathan Avatar answered Sep 28 '22 03:09

Sudhir Jonathan