以上で、準備は完了です。
まずは、Google App Engine用のテストプログラムで重要な箇所を見ていきましょう。
@Override
public void setUp() throws Exception {
super.setUp();
ApiProxy.setEnvironmentForCurrentThread(new TestEnvironment()); // (1)
ApiProxy.setDelegate(new ApiProxyLocalImpl(new File(".")) { // (2)
});
}
public void testSendMail() {
ApiProxyLocalImpl proxy = (ApiProxyLocalImpl) ApiProxy.getDelegate(); // (3)
LocalMailService mailService = (LocalMailService) proxy.getService("mail"); // (4)
// ;
// ;
}
- Google App Engine用の環境変数を設定します(
TestEnvironmentクラスは、後述します)。 ApiProxyにローカル用のDelegateを設定します。- テストをする時に
Delegateを取得します。Delegateは全サービスにアクセスできるクラスです。 getService(String)でテストしたいサービスを取得します。引数は、サービスのパッケージ名になります。
