My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
GAEPlugin  
Google App Engine plugin uses current GAE local unit testing
Featured, Cookbook
Updated Oct 19, 2010 by ajglo...@gmail.com

Introduction

You can test GAE applications locally with easyb -- using the GAE plugin, you can do everything that Google's local unit testing services provide. You can see what's provided by Google on their local unit testing documentation.

To use the GAE plugin in easyb, simply use the using "GAE" phrase (along with placing the proper jar files in our classpath). What's more, the following objects are available to you:

  • localServiceHelper
    • represents the local instance of Google's LocalServiceTestHelper
  • datastore
    • represents the local instance of Google's DatastoreService
  • memcache
    • represents the local instance of Google's MemcacheService
  • user
    • represents the local instance of Google's UserService
  • queue
    • represents the local instance of default queue (i.e. QueueFactory.getDefaultQueue())
  • localTaskQueue
    • represents the local instance of LocalTaskQueueTestConfig.getLocalTaskQueue()

The GAE plugin for easyb works like so:

import com.google.appengine.api.datastore.Entity
import com.google.appengine.api.datastore.Query
import com.google.appengine.api.labs.taskqueue.TaskOptions
import com.google.appengine.api.labs.taskqueue.dev.QueueStateInfo

using "GAE"

scenario "Creating a simple entity easily", {
  given "a ds instance", {
    ds = datastore
  }
  then "it should be found and contain all relevant datapoints", {
    ds.prepare(new Query("yam")).countEntities().shouldBe 0
    ds.put(new Entity("yam"));
    ds.put(new Entity("yam"));
    ds.prepare(new Query("yam")).countEntities().shouldBe 2
  }
}

scenario "Using memcache should work", {
  given "a memcache instance", {
    ms = memcache
  }
  then "it should support storing information", {
    ms.contains("yar").shouldBe false
    ms.put("yar", "foo")
    ms.contains("yar").shouldBe true
  }
}

scenario "Using user service should work", {
  given "a user service instance", {
    userService = user
  }
  and "everything has been set up properly", {
    localServiceHelper.setEnvIsAdmin(true)
    localServiceHelper.setEnvIsLoggedIn(true)
  }
  then "it should be admin", {
    userService.isUserAdmin().shouldBe true
  }
}

scenario "Using task service should work", {
  given "a task", {
    queue.add(TaskOptions.Builder.taskName("task29"))
  }
  then "it should be in the queue", {
    Thread.sleep(1000)
    QueueStateInfo qsi = localTaskQueue.getQueueStateInfo().get(queue.getQueueName())
    qsi.getTaskInfo().size().shouldBe 1
    qsi.getTaskInfo().get(0).getTaskName().shouldBe "task29"
  }
}

Details

This plugin functions at the story level; that is, the setup is done before a story is run and the tear down is after a story is complete -- thus, these objects live for an entire story (i.e. many scenarios). If you need to reset state between scenarios, then consider using different stories.

Download the GAE plugin


Sign in to add a comment
Powered by Google Project Hosting