Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integration tests for Google App Engine (java)

I'm trying to develop some effective integration tests for my GAE/j application. I'm familiar with https://developers.google.com/appengine/docs/java/tools/localunittesting -- these tools are great for small unit tests. I'm now interested in developing integration tests that test actual web requests. For example, I'd like to test that web.xml is mapping servlets and filters to the expected URLs and test that my JSPs generate what I expect.

My aim was to bring up a local development server inside the JVM, which I could fire requests against. I'm open to other integration strategies, though; as I say above, I just want to effectively test JSP generation and other request-level features.

I've managed to use DevAppServerFactory to start a development server in the same JVM. However, it appears that the DevAppServer this generates uses a separate classloader from the main JVM. This makes testing a lot more challenging--I can't use any of the local unittesting Local*TestConfig classes to control behavior of this server. Similarly, I can't "roll my own" hooks for modifying behavior via e.g. statics, since the statics I can mutate in the test harness aren't the same statics the DevAppServer is looking at. This makes it challenging to skip features not central to the current test (e.g. requiring login), to inject failures, to inject mocks, etc. This really limits how completely and efficiently I can test my code.

I've found a real dearth of documentation on the web for integration testing with App Engine. I'm sure someone has done this before...are there any tips or resources out there you can share?

like image 827
user1566136 Avatar asked Jul 31 '12 15:07

user1566136


1 Answers

Basically, you need to do two things:

  1. Add two servlets (or whatever), which must be only enabled during testing, which allow you to invoke setup and teardown on the helper remotely.
  2. Make your servlet engine serve requests in a completely single-threaded way. This is needed because for some reason, the Helper class Google provides only takes effect in the current thread.
like image 163
Robin Green Avatar answered Sep 21 '22 16:09

Robin Green