我正在尝试使用gwt junit测试我的gwt应用程序,但似乎无法正确设置以测试objectify。所有的教程都演示了测试DataStore而不是objectify (这是更高级别的数据库服务),我的测试基类如下所示:
public class TestBase {
private static final LocalServiceTestHelper helper =
new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig());
protected static ObjectifyFactory fact;
@BeforeClass
public static void setUp() {
helper.setUp();
fact = new ObjectifyFactory() {
@Override
public Objectify begin(ObjectifyOpts opts)
{
opts.setSessionCache(false);
return super.begin(opts);
}
};
}
@AfterClass
public static void tearDown() {
helper.tearDown();
}
}然后我有扩展基类的类:
public class UserServiceTest extends TestBase{
private User inactiveUser;
private UserService us;
Objectify _ofy;
@Rule
public ExpectedException thrown = ExpectedException.none();
@Before
public void beforeTest() {
//Register the classes used in the test
fact.register(User.class);
us = new UserService();
inactiveUser = new User();
}
@Test
public void basicTest(){
Objectify ofy = ObjectifyService.begin();
ofy.put(inactiveUser); //This fails with exception: An exception occurred: com.google.apphosting.api.ApiProxy$CallNotFoundException
//My goal is to reach these test but "addUser" uses also objectify
//UserService.addUser("shpungin@gmail.com", "bye");
//assertNotNull(inactiveUser.get_id());
}你知道我做错了什么吗?我找遍了互联网,没有找到任何解决方案(有些人甚至说要从.classpath中删除app-engine-sdk,但它似乎不起作用。
谢谢。
发布于 2012-06-02 00:31:31
我解决了这个问题。
尽管com.google.apphosting.api.ApiProxy应该是应用程序引擎的一部分,但是一些jars仍然需要放在.classpath中:
${SDK_ROOT}/lib/testing/appengine-testing.jar
${SDK_ROOT}/lib/impl/appengine-api.jar
${SDK_ROOT}/lib/impl/appengine-api-labs.jar
${SDK_ROOT}/lib/impl/appengine-api-stubs.jar //我错过了这个
另外,我把我的app-engine升级到了v1.6.4.1(也许这也有帮助)。
https://stackoverflow.com/questions/10851440
复制相似问题