我结束了创建以下BaseTest类,并具有所有我的测试从继承:
package com.example;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.dev.HighRepJobPolicy;
import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig;
import com.google.appengine.tools.development.testing.LocalServiceTestHelper;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
public class BaseTest {
public static final class Policy implements HighRepJobPolicy {
static boolean shouldApply = false;
public static void applyAll() {
shouldApply = true;
}
public static void applyNone() {
shouldApply = false;
}
@Override
public boolean shouldApplyNewJob(Key entityGroup) {
return shouldApply;
}
@Override
public boolean shouldRollForwardExistingJob(Key entityGroup) {
return shouldApply;
}
}
public final LocalServiceTestHelper helper =
new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig()
.setAlternateHighRepJobPolicyClass(Policy.class));
@Before
public void setUp() {
helper.setUp();
}
@After
public void tearDown() {
helper.tearDown();
}
}
然后测试可以是这样的形式:
@Test
public void thingShouldDoX() throws Exception {
Policy.applyAll();
// Do setup here, everything inside will be consistent.
Policy.applyNone();
// Run code under test here, without consistency.
}
你说的“最好的意思?”我迄今为止所做的关于“最终一致的Google App Engine数据”的轶事搜索表明,“最终”被定义为相对较短的时间段(大多数情况下不到一秒钟)。 –
改编我的问题。单元测试文档建议将未应用的工作百分比设置为100,这意味着全局(非祖先)查询将始终无法看到更改,因此我不确定是否在此等待工作。 –