2012-06-01 239 views
1

我想用gwt junit测试我的gwt应用程序,但似乎无法正确设置事物,使得对象化测试。 所有教程演示了测试数据存储而不是客体(这是数据库服务的更高层次) 我进行测试的基类看起来是这样的:gwt junit测试对象化

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("[email protected]", "bye"); 
    //assertNotNull(inactiveUser.get_id()); 
} 

你知道我做错了什么吗?我找遍了整个互联网,没有发现溶液(有的甚至说要删除的.classpath应用引擎-SDK,但dosent似乎工作。

谢谢。

+1

这与GWT有什么关系?我在这里只看到普通的JUnit,AppEngine和Objectify。 –

+0

嗨托马斯,我的项目是一个gwt项目,我正在运行gwt junit测试。 – Michael

+0

那么,这是一个JUnit 4测试,而不是GWTTestCase,所以它很难被称为“gwt junit测试”;这只是一个普通的JUnit测试,它没有任何与GWT相关的测试;就这个测试而言,在同一个项目中使用GWT并不重要。 –

回答

1

我解决了这个。

虽然com.google.apphosting.api.ApiProxy应该是应用引擎的一部分 一些罐子仍然需要在里面的.classpath:

$ {} SDK_ROOT /lib/testing/appengine-testing.jar

$ {SDK_ROOT}/lib/i MPL/AppEngine上 - api.jar中

$ {} SDK_ROOT /lib/impl/appengine-api-labs.jar

$ {} SDK_ROOT // /lib/impl/appengine-api-stubs.jar这我错过了一个

另外我升级了我的应用程序引擎到v 1.6.4.1(也许这也有帮助)。