我想编写自动化测试,在本地开发web服务器上运行。针对底层服务(https://cloud.google.com/appengine/docs/java/tools/localunittesting)编写测试很容易,但我想测试我的整个堆栈。我可以使用Runtime.exec()启动和终止服务器,但我希望有人开发了一个更优雅的解决方案。
发布于 2016-04-08 05:09:28
我在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));
}
}https://stackoverflow.com/questions/36487091
复制相似问题