尝试使用maven 3.2.1运行我的GAE 1.9.0项目的单元测试。数据存储相关测试失败:
java.util.ServiceConfigurationError:
com.google.appengine.tools.development.LocalRpcService:
Provider com.google.appengine.api.datastore.dev.LocalDatastoreV4Service
could not be instantiated: java.lang.NoClassDefFoundError:
com/google/apphosting/datastore/DatastoreV4$LookupRequestOrBuilder
我明白这意味着我错过了依赖。似乎无法找到有关如何正确配置数据存储区测试的pom.xml的文档。我打电话时测试崩溃了
helper.setup()
帮帮人:
public final LocalServiceTestHelper helper = new LocalServiceTestHelper(
new LocalDatastoreServiceTestConfig(),
new LocalTaskQueueTestConfig(),
new LocalBlobstoreServiceTestConfig(),
new LocalUserServiceTestConfig()));
引用:
https://developers.google.com/appengine/docs/java/tools/maven#junit_dependencies_optional
我的pom.xml中的测试依赖项
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-testing</artifactId>
<version>${appengine.target.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-stubs</artifactId>
<version>${appengine.target.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-labs</artifactId>
<version>${appengine.target.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>3.2.1.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>spring</groupId>
<artifactId>spring-mock</artifactId>
<version>1.0.2</version>
<scope>test</scope>
</dependency>
堆栈跟踪的其余部分:
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
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:606)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: java.lang.NoClassDefFoundError: com/google/apphosting/datastore/DatastoreV4$LookupRequestOrBuilder
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2493)
at java.lang.Class.getConstructor0(Class.java:2803)
at java.lang.Class.newInstance(Class.java:345)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:373)
... 42 more
Caused by: java.lang.ClassNotFoundException: com.google.apphosting.datastore.DatastoreV4$LookupRequestOrBuilder
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
答案 0 :(得分:2)
在我的情况下,将testCompile 'com.google.appengine:appengine-tools-sdk:1.9.24'
添加到我的build.gradle中修复它。 (我正在使用gradle - maven等价物应该是相同的。)以下是我的测试依赖项:
// Test
testCompile "junit:junit:4.12"
testCompile 'com.google.appengine:appengine-testing:1.9.24'
testCompile 'com.google.appengine:appengine-api-labs:1.9.24'
testCompile 'com.google.appengine:appengine-api-stubs:1.9.24'
testCompile 'com.google.appengine:appengine-tools-sdk:1.9.24'
我不知道发生了什么变化 - 它过去没有那种依赖性。但至少可以解决这个问题。
答案 1 :(得分:0)
我不知道你们是否解决了,但是使用GAE版本1.8.2为我工作了!