2016-04-07 17 views
1

ローカル開発Webサーバーに対して実行される自動テストを書きたいと思います。基礎となるサービス(https://cloud.google.com/appengine/docs/java/tools/localunittesting)に対してテストを書くのは簡単ですが、完全なスタックをテストしたいと思います。私はRuntime.exec()を使ってサーバを起動して終了することができましたが、誰かがより洗練されたソリューションを開発したいと思っています。JUnitからGoogle App Engine Java開発サーバーを起動するにはどうすればよいですか?

答えて

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)); 
    } 
} 
関連する問題