NullPointerException在Google App Engine LocalSErviceTestHelper上调用tearDown() [英] NullPointerException calling tearDown() on Google App Engine LocalSErviceTestHelper

查看:163
本文介绍了NullPointerException在Google App Engine LocalSErviceTestHelper上调用tearDown()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Google App Engine Java应用编写测试(集成和单元),该应用严重依赖Google App Engine服务,例如Memcache和Datastore。为了在本地使用这些服务测试我的应用程序,我在所有测试用例的父类中都有这一行:

  private final LocalServiceTestHelper helper = new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig(),new LocalMemcacheServiceTestConfig()); 

我用这个函数调用开始每个测试(通过TestNG的 @BeforeMethod < code $>注解):

  helper.setUp(); 

我用这个函数调用结束每个测试(通过TestNG的 @AfterMethod 注解):

  helper.tearDown(); 

(以下是对 TestNG注释针对Google App Engine的Java Runtime的本地单元测试,以防万一您需要它。特别是对于后者的链接,请注意,我的代码严格遵循Google提供的示例)



需要注意的是,Java应用程序中的一个servlet使用MemcacheService的一个实例。它由Guice注入servlet的构造函数中。



现在,我构建我的代码并通过调用 mvn clean install ,它将启动一个 Jetty实例并在代码编译完成后运行我的测试。 很让我懊恼的是,在TestNG报告批量测试失败之前,我得到了这个堆栈跟踪:

  SEVERE :收到的异常消除com.google.appengine.tools.development.testing.LocalMemcacheServiceTestConfig类型的配置
java.lang.NullPointerException
com.google.appengine.tools.development.testing.LocalServiceTestHelper.getLocalService (LocalServiceTestHelper.java:495)在com.google.appengine.tools.development.testing.LocalMemcacheServiceTestConfig.getLocalMemcacheService(LocalMemcacheServiceTestConfig.java:71)

在的列举.LocalMemcacheServiceTestConfig.tearDown(LocalMemcacheServiceTestConfig.java:47)
在com.google.appengine.tools.development.testing.LocalServiceTestHelper.tearDown(LocalServiceTestHelper.java:438)
在com.ea.pogosocial.AbstractTest .tearDown(AbstractTest.java:65)
at sun.reflect.NativeMethodAccessorImpl.invoke0(本地方法)
at sun.reflect.Nativ eMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
在java.lang.reflect.Method.invoke(Method.java:616)在org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)

在org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
在org.testng .internal.Invoker.invokeConfigurations(Invoker.java:213)
在org.testng.internal.Invoker.invokeMethod(Invoker.java:796)
在org.testng.internal.Invoker.invokeTestMethod(祈求的.java:在org.testng.internal.TestMethodWorker.invokeTestMethods 907)在org.testng.internal.Invoker.invokeTestMethods
(Invoker.java:1237)
(TestMethodWorker.java:127)
在org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
在java.util.concurrent。的ThreadPoolExecutor $ Worker.run(ThreadPoolExe cutor.java:603)
在java.lang.Thread.run(Thread.java:679)



我已经尝试了几乎所有我能想到解决问题的方法,但我仍然遇到了tearDown()问题,这实际上困扰着我。在put()和get()旁边,我没有对我的servlet中的memcache实例做任何事情。有没有人有任何想法,我应该做什么?



如果需要更多信息或代码,我会很乐意提供。有一点需要注意:当我使用 mvn gae:run 启动我的Jetty服务器并且通过Eclipse执行TestNG测试时,我不会遇到这个问题。也许这是因为我的servlet被注入了非本地的memcache单元测试帮助实例,而是一个memcache服务的实际版本。

div>

我有这个完全相同的错误。我的问题是Google App Engine SDK依赖项的版本号不匹配。

>
  • appengine-api-1.0-sdk:1.8.1.1
  • appengine-api-labs:1.8.1.1
  • appengine-api-stubs:1.8.1.1
  • appengine-testing:1.8.1.1

  • appengine-tools-sdk: 1.7.2 我曾经更新过appengine-tools-sdk与其他依赖项相同的版本再次通过。


    I am writing tests (integration and unit) for a Google App Engine Java app that relies heavily on Google App Engine services such as Memcache and Datastore. In order to test my application locally using these services, I have this line in the parent class of all my test cases:

    private final LocalServiceTestHelper helper = new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig(), new LocalMemcacheServiceTestConfig());
    

    I begin every test with this function call (via TestNG's @BeforeMethod annotation):

    helper.setUp();
    

    And I end every test with this function call (via TestNG's @AfterMethod annotation):

    helper.tearDown();
    

    (Here's a reference to TestNG annotations and local unit testing for Google App Engine's Java Runtime, in case you need it. Especially for the latter link, note that my code strictly follows the examples given by Google)

    One thing to note is that one of my servlets in the Java app uses an instance of MemcacheService. It is injected into the servlet's constructor by Guice.

    Now, I build my code and run it via a call to mvn clean install, which will start an instance of Jetty and run my tests after the code has been compiled. Much to my chagrin, I get this stack trace printed before TestNG reports mass test failure:

    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)
    

    I have tried almost everything I can think of to fix the problem, but I still run into this tearDown() problem, which is really stumping me. Beside put() and get(), I don't do anything fancy with the memcache instance in my servlet. Does anyone have any ideas as to what I should do?

    If more information or code is needed, I will be glad to provide. One thing to note: when I instead start my Jetty server with mvn gae:run and I execute the TestNG tests through Eclipse, I do not run into this issue. Perhaps this is because my servlet is being injected a non-local unit test helper instance of memcache, but rather an actual version of a memcache service.

    解决方案

    I had this exact same error. The problem for me was a mismatch in the version numbers for the Google App Engine SDK dependencies

    I had:

    • appengine-api-1.0-sdk: 1.8.1.1
    • appengine-api-labs: 1.8.1.1
    • appengine-api-stubs: 1.8.1.1
    • appengine-testing: 1.8.1.1
    • appengine-tools-sdk: 1.7.2

    Once I updated appengine-tools-sdk to be the same version as the rest of the dependencies, my tests started passing again.

    这篇关于NullPointerException在Google App Engine LocalSErviceTestHelper上调用tearDown()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆