MemcacheやDatastoreなどのGoogleAppEngineサービスに大きく依存するGoogleAppEngine Javaアプリのテスト(統合とユニット)を作成しています。これらのサービスを使用してアプリケーションをローカルでテストするために、すべてのテストケースの親クラスに次の行があります。
private final LocalServiceTestHelper helper = new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig(), new LocalMemcacheServiceTestConfig());
私はすべてのテストをこの関数呼び出しで開始します(TestNGの@BeforeMethod
アノテーションを介して):
helper.setUp();
そして、私はこの関数呼び出しですべてのテストを終了します(TestNGの@AfterMethod
アノテーションを介して):
helper.tearDown();
(必要に応じて、Google App EngineのJavaランタイムのTestNGアノテーションとローカル単体テストへの参照があります。特に後者のリンクの場合、私のコードはGoogleが提供する例に厳密に従っていることに注意してください)
注意すべき点の1つは、Javaアプリのサーブレットの1つがMemcacheServiceのインスタンスを使用していることです。これは、Guiceによってサーブレットのコンストラクターに挿入されます。
ここで、コードをビルドし、への呼び出しを介して実行します。これにより、 Jettymvn clean install
のインスタンスが起動し、コードがコンパイルされた後にテストが実行されます。残念なことに、 TestNGが大量テストの失敗を報告する前に、このスタックトレースが印刷されます。
SEVERE: Received exception tearing down config of type com.google.appengine.tools.development.testing.LocalMemcacheServiceTestConfig
java.lang.NullPointerException
at com.google.appengine.tools.development.testing.LocalServiceTestHelper.getLocalService(LocalServiceTestHelper.java:495)
at com.google.appengine.tools.development.testing.LocalMemcacheServiceTestConfig.getLocalMemcacheService(LocalMemcacheServiceTestConfig.java:71)
at com.google.appengine.tools.development.testing.LocalMemcacheServiceTestConfig.tearDown(LocalMemcacheServiceTestConfig.java:47)
at com.google.appengine.tools.development.testing.LocalServiceTestHelper.tearDown(LocalServiceTestHelper.java:438)
at com.ea.pogosocial.AbstractTest.tearDown(AbstractTest.java:65)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:796)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:907)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1237)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:679)
私は問題を解決するために考えられるほとんどすべてのことを試みましたが、それでもこのtearDown()の問題に遭遇し、それは本当に私を困惑させています。put()とget()以外は、サーブレットのmemcacheインスタンスで特別なことは何もしていません。誰かが私が何をすべきかについて何か考えがありますか?
さらに情報やコードが必要な場合は、喜んで提供させていただきます。注意すべき点が1つあります。代わりに、Jettyサーバーをで起動し、mvn gae:run
Eclipseを介してTestNGテストを実行しても、この問題は発生しません。おそらくこれは、サーブレットにmemcacheの非ローカル単体テストヘルパーインスタンスが注入されているためですが、実際のバージョンのmemcacheサービスが注入されているためです。