Unable to use GAE Datastore test helper and User service test helper together
I am trying to write JUnit4 tests for my java app that uses both data
store and users service. I followed the code sample from here and added a
user service test helper.
My code is pasted below.
public class LocalDatastoreTest {
private final LocalServiceTestHelper userserviceTestHelper =
new LocalServiceTestHelper(new LocalUserServiceTestConfig())
.setEnvIsAdmin(true).setEnvIsLoggedIn(true);
private final LocalServiceTestHelper datastoreTestHelper =
new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig());
@Before
public void setUp() {
userserviceTestHelper.setUp();
datastoreTestHelper.setUp();
}
@After
public void tearDown() {
datastoreTestHelper.tearDown();
userserviceTestHelper.tearDown();
}
// run this test twice to prove we're not leaking any state across tests
private void doTest() {
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
assertEquals(0, ds.prepare(new
Query("yam")).countEntities(withLimit(10)));
ds.put(new Entity("yam"));
ds.put(new Entity("yam"));
assertEquals(2, ds.prepare(new
Query("yam")).countEntities(withLimit(10)));
}
@Test
public void testInsert1() {
doTest();
}
@Test
public void testInsert2() {
doTest();
}
}
When I run the tests it I get a null pointer exception when calling the
tearDown method.
Has anyone used both the data store and user service test helpers together
? Any tips/suggestions would be appreciated.
Regards,
Sathya
No comments:
Post a Comment