,這是你做了什麼如何。如果你想使用的數據存儲服務來執行JUnit測試使用ObjectifyService在JUnit測試
LocalServiceTestHelper helper =
new LocalServiceTestHelper(new LocalMemcacheServiceTestConfig(),new LocalDatastoreServiceTestConfig());
@Before
public void setUp() {
helper.setUp();
}
@After
public void tearDown() {
helper.tearDown();
}
@Test
public void testInsert1() {
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)));
}
我曾嘗試用物化
Public class myofyTest{
@Entity
private class Food{
@id Long id;
String foodtype;
public Food(String food){
foodtype = food ;
}
}
static{
ObjectifyService.register(Food.class);
}
LocalServiceTestHelper helper = new LocalServiceTestHelper
(new LocalMemcacheServiceTestConfig(),new LocalDatastoreServiceTestConfig());
@Before
public void setUp() {
helper.setUp();
}
@After
public void tearDown() {
helper.tearDown();
}
@Test
public void testInsert1() {
Food food = new Food("yam");
ofy().save().entities(food).now();
}
}
上面的測試但我得到這種異常
java.util.ServiceConfigurationError: com.google.appengine.tools.development.
LocalRpcService: Provider com.google.appengine.api.datastore.dev.
LocalCloudDatastoreV1Service could not be instantiated
你如何實施這種測試使用ObectifyService而不是DatastoreService?
我收到2個錯誤。無法解析'ObjectifyService.begin()'中的方法begin()和檢索食物的代碼中的方法'doTest',我收到錯誤**無法訪問com.google.appengine.api.datastore.QueryResultIterable **放置'.... ofy()。load().....' –
@gikarasojo你正在檢查我分享的所有依賴關係嗎? – Devrim