If you want to test a class which depends on Google App Engine infrastructure, such as data storing functionality with "PersistenceManagerFactory", you should set up LocalServiceTestHelper before testing.
I don't tell you the details very much, but I will show you the minimum test setup in the code below.
This code was enough for me to test my data access object functionality.
package com.dukesoftware.gaej.test;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig;
import com.google.appengine.tools.development.testing.LocalServiceTestHelper;
public class GoogleAppEngineTest {
private static final LocalServiceTestHelper helper =
new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig());
@BeforeClass
public static void setUp() {
helper.setUp();
}
@AfterClass
public static void tearDown() {
helper.tearDown();
}
@Test
public void testSomething()
{
// test functionality which depends on datastore, etc.
}
}
コメント