我有一些使用统计数据的代码,我想测试这个方法。为了测试这一点,我有以下代码:
@RunWith(MockitoJUnitRunner.class)
public class MyTest {
private final LocalServiceTestHelper helper =
new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig());
@Before
public void setUp()
throws Exception {
helper.setUp();
}
@After
public void tearDown() {
helper.tearDown();
}
@Test
public void getKinds() {
DatastoreService datastoreService = DatastoreServiceFactory.getDatastoreService();
assertEquals(0, datastoreService.prepare(new Query("yam")).countEntities(withLimit(10)));
datastoreService.put(new Entity("yam"));
datastoreService.put(new Entity("yam"));
Iterable<Entity> kinds = datastoreService.prepare(new Query("__Stat_Kind__")).asIterable();
System.out.println("In 'getKinds'");
for (Entity kind : kinds) {
System.out.println(kind.getProperty("kind_name").toString());
}
}
}我希望这个能打印出来
在getKinds中 山药
但我只得到了
在getKinds中
我是在代码中遗漏了什么,还是有其他方法来测试数据存储统计数据?谢谢。
参考链接:
https://developers.google.com/appengine/docs/java/tools/localunittesting https://developers.google.com/appengine/docs/java/datastore/stats
发布于 2014-07-30 20:18:18
您确定在检查时数据存储是一致的吗?
数据存储首先将put提交到"main“表,然后”应用“该更改将其推送到其他平板/索引.
在提交部分之后返回put,而不一定在应用部分之后返回,这可以解释为什么您的类在放入实体之后似乎是空的。
您可以执行"while“,检查有多少实体,并在"yam”存在后继续前进,也可以简单地使用祖先查询来强制执行强一致性。
https://stackoverflow.com/questions/25042502
复制相似问题