David Chandler's Journal of Java Web and Mobile Development

  • David M. Chandler

    Web app developer since 1994 and Google Cloud Platform Instructor now residing in Colorado. Besides tech, I enjoy landscape photography and share my work at ColoradoPhoto.gallery.

  • Subscribe

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 224 other followers

  • Sleepless Nights…

    October 2009
    S M T W T F S
  • Blog Stats

    • 1,034,589 hits

Unit testing the AppEngine Datastore with JDO

Posted by David Chandler on October 19, 2009

I’ll admit, I was lazy at first and didn’t write server-side unit tests for my JDO persistence methods. I was effectively doing testing via trial and error from the client, which has two drawbacks: 1) if you make a change to server-side code, you have to restart the hosted development environment, which takes a while, and 2) since GWT doesn’t know about all of JDO’s exceptions, JDO errors in server-side code are frequently masked by GWT serialization errors involving the JDOFatalUserException or some such.

Google provides a recipe for AppEngine unit testing, but their coverage of testing the Datastore is incomplete. Thankfully, AppEngineFan has solved this and published a blog post and some nice code to help test AppEngine JDO calls. All I needed was the three classes in the com.appenginefan.toolkit.unittests package. Just extend BaseTest, call the newPersistenceManager() method, and you’re off and running.

Note: this post applies to testing only in the local development environment. I doubt you can run unit tests in the AppEngine production environment, but if I’m wrong about that, please post a comment as I’d sure like to know about it.

One Response to “Unit testing the AppEngine Datastore with JDO”

  1. […] unit testing. I don’t actually need an alternate PM yet as it is handled transparently by my AppEngine test environment, but I thought it would be easier to do it sooner rather than later, so here […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: