2016-04-07 91 views

回答

0

我找到了答案the Javadocs。使用DevAppServerTestRunner

@RunWith(DevAppServerTestRunner.class) 
@DevAppServerTest(EndToEndTest.TestConfig.class) 
public class EndToEndTest { 

    private final LocalServiceTestHelper testHelper = new LocalServiceTestHelper(
    new LocalURLFetchServiceTestConfig(), new LocalDatastoreServiceTestConfig()); 

    public static class TestConfig extends BaseDevAppServerTestConfig { 

    public File getSdkRoot() { 
     return new File(...); 
    } 

    public File getAppDir() { 
     return new File(...); 
    } 

    public List<URL> getClasspath() { 
     return Arrays.asList(...); 
    } 
    } 

    @Before 
    public void setUpHelper() { 
    testHelper.setUp(); 
    } 

    @After 
    public void tearDownHelper() { 
    testHelper.tearDown(); 
    } 

    @Test 
    public void testEndToEnd() throws Exception { 
    URLFetchService fetchService = URLFetchServiceFactory.getURLFetchService(); 
    HTTPResponse resp = fetchService.fetch(new URL("http://localhost:8080/insertFoo?id=33")); 
    Assert.assertEquals(200, resp.getResponseCode()); 
    DatastoreServiceFactory.getDatastoreService().get(KeyFactory.createKey("foo", 33)); 
    } 
} 
相關問題