Testing GAE Task Queue with jUnit

Volodymyr Shtenovych News RSS feedNews RSS feed

Testing GAE Task Queue with jUnit

It is generally agreed that automated testing is extremely important for software development process. It is so, despite the actual product’s complexity. I personally think that the primary reason of automated tests usage is possibility  to make changes to your code and quickly check whether the very basic business workflow still works. And because of that I dislike unit testing which I think makes sense not so much often and only to verify some of isolated components with complicated logic. Putting effort into unit-testing 50-60-70-80-90% coverage and even more of application code is in vain  - it takes too much time and it causes a problem it’s supposed to solve - when you have so much percentage of unit-tested code you are not able to make changes to your software quickly, 5 minutes refactoring causes 1 hour of fixing tests.

When I talk about automated tests I usually mean integration tests - the ones which could be implemented either as unit tests or using any of UI clicking tool (the last one is usually harder to maintain).

While working at Emails to RSS Forwarding service I faced the problem that app engine local testing environment does not support Task Queue but the service itself uses Task Queue very extensively for processing, archiving, RSS generation and maintenance tasks. Well, I exaggerated a bit, actually Google App Engine does support local testing using Task Queue - but in a very limited way at this point - the only thing it allows to schedule asynchronous task during testing and to verify that the task is added to particular queue and nothing more. If business workflows of your application depend on asynchronous jobs as in my case, possibility to run them under jUnit is necessary for successful integration testing. To resolve that problem in a way GAE considers it as legal I implemented the LocalTaskQueueCallback to run the right servlet with the right parameters. The code of it can be downloaded from here TaskQueueRunner.java To use this task queue runner in your application put the TaskQueueRunner class as a parameter to LocalTaskQueueTestConfig.setCallbackClass method before you do LocalServiceTestHelper.setUp().

If you choose to disable automatically asynchronous tasks running to be able to manually check that everything is scheduled correctly and then run the async jobs TaskQueueRunner provides two overloads of processTasks static method.

Me in Twitter
Brainbench test C# 4.0
Volodymyr Shtenovych