【问题标题】:gwt junit for testing objectify用于测试objectify的gwt junit
【发布时间】:2012-06-06 18:19:12
【问题描述】:

我正在尝试使用 gwt junit 测试我的 gwt 应用程序,但似乎无法正确设置以使对象化被测试。 所有教程都演示了测试 DataStore 但不对象化(这是更高级别的数据库服务) 我的测试基类如下所示:

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,但它似乎有效。

谢谢。

【问题讨论】:

  • 这与 GWT 有什么关系?我在这里只看到普通的 JUnit、AppEngine 和 Objectify。
  • 嗨,Thomas,我的项目是一个 gwt 项目,我正在运行 gwt junit 测试。
  • 嗯,这是一个 JUnit 4 测试,而不是 GWTTestCase,所以它很难被称为“gwt junit 测试”;这只是一个简单的 JUnit 测试,其中没有任何 GWT 相关的内容;就这个测试而言,是否在同一个项目中使用 GWT 并不重要。

标签: unit-testing google-app-engine junit objectify


【解决方案1】:

我解决了这个问题。

虽然 com.google.apphosting.api.ApiProxy 应该是应用引擎的一部分 有些罐子仍然需要在 .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 //这个我错过了

我还将我的应用引擎升级到 v 1.6.4.1(也许这也有帮助)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-05
    • 2018-02-20
    • 1970-01-01
    • 2017-05-28
    相关资源
    最近更新 更多