App Engine documentation gives an example of unit testing task queues, which works fine for the \"default\" queue, but I need a unit test for non-default queues.
I\'
When using the gradle plugin, make sure to include:
testCompile 'com.google.appengine:appengine-tools-sdk:1.9.9'
Yes, you configure it just like the other unit test harness classes and pass it the path to your test queue.xml, mine happens to be in /src/test/resources (the usual place for a maven project)
Here's a snippet from my base junit test class...
static {
dir = System.getProperty("user.dir") + "/src/test/resources/queue.xml";
}
private final LocalServiceTestHelper helper = new LocalServiceTestHelper(
new LocalDatastoreServiceTestConfig(),
new LocalTaskQueueTestConfig().setQueueXmlPath(dir));
And then you can do things like (and sorry if this is out of context, but it should give you the idea.. and it's groovy so it might look odd)
//do something that might trigger a queue to run...
NotificationService.getInstance().doNotification(interaction)
LocalTaskQueue taskQueue = LocalTaskQueueTestConfig.getLocalTaskQueue()
Map allQueues = taskQueue.getQueueStateInfo()
QueueStateInfo mailQueue = allQueues.get(EmailTaskQueue.MAIL_QUEUE)
assert mailQueue.getCountTasks() == 1
More details on Rick Mangi's comment. If you get an error like:
java.lang.NoClassDefFoundError: org/mortbay/xml/XmlParser
add this to your pom.xml:
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-tools-sdk</artifactId>
<version>${gae.version}</version>
</dependency>