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.
Unit testing with JDO PersistenceManager injected via Guice « TurboManage said
[…] 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 […]