2012-06-01 240 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(也許這也有幫助)。