我正在尝试使用Google应用引擎提供的本地测试帮助程序对我使用objectify的应用进行单元测试。但是,某些测试失败并显示以下消息;
com.google.apphosting.api.ApiProxy$CallNotFoundException: The API package 'datastore_v3' or call 'Put()' was not found.
at com.google.apphosting.api.ApiProxy$1.get(ApiProxy.java:164)
at com.google.apphosting.api.ApiProxy$1.get(ApiProxy.java:162)
at com.google.appengine.api.utils.FutureWrapper.get(FutureWrapper.java:90)
at com.google.appengine.api.datastore.FutureHelper$CumulativeAggregateFuture.get(FutureHelper.java:145)
at com.google.appengine.api.utils.FutureWrapper.get(FutureWrapper.java:90)
at com.googlecode.objectify.impl.ResultAdapter.now(ResultAdapter.java:29)
at com.googlecode.objectify.util.ResultWrapper.translate(ResultWrapper.java:20)
at com.googlecode.objectify.util.ResultWrapper.translate(ResultWrapper.java:1)
at com.googlecode.objectify.util.ResultTranslator.nowUncached(ResultTranslator.java:21)
at com.googlecode.objectify.util.ResultCache.now(ResultCache.java:27)
at com.googlecode.objectify.util.ResultWrapper.translate(ResultWrapper.java:20)
at com.googlecode.objectify.util.ResultWrapper.translate(ResultWrapper.java:1)
at com.googlecode.objectify.util.ResultTranslator.nowUncached(ResultTranslator.java:21)
at com.googlecode.objectify.util.ResultCache.now(ResultCache.java:27)
这是我的代码:
private final LocalServiceTestHelper helper = new LocalServiceTestHelper(
new LocalDatastoreServiceTestConfig(),
new LocalMemcacheServiceTestConfig());
@BeforeMethod(alwaysRun = true)
public void setUp() {
helper.setUp();
}
.....
//In class constructor
ObjectifyService.register(SomeClass.class);
.....
@AfterMethod(alwaysRun = true)
public void tearDown() {
helper.tearDown();
}
public void doTest {
SomeClass value = ......
ofy().save().entity(value).now(); //throws error
}
这是我的依赖树:
[INFO] | +- com.google.guava:guava-collections:jar:r03:compile
[INFO] | | +- com.google.guava:guava-annotations:jar:r03:compile
[INFO] | | \- com.google.guava:guava-primitives:jar:r03:compile
[INFO] | | \- com.google.guava:guava-base:jar:r03:compile
[INFO] | \- com.google.inject.extensions:guice-servlet:jar:3.0:compile
[INFO] +- com.google.inject:guice:jar:3.0:compile
[INFO] | +- com.google.api-client:google-api-client:jar:1.11.0-beta:compile
[INFO] | | \- com.google.oauth-client:google-oauth-client:jar:1.11.0-beta:compile
[INFO] | | +- com.google.code.findbugs:jsr305:jar:1.3.9:compile
[INFO] | | \- com.google.guava:guava:jar:11.0.1:compile
[INFO] | +- com.google.appengine:appengine-api-1.0-sdk:jar:1.7.2:compile
[INFO] | \- com.googlecode.objectify:objectify:jar:4.0a4:compile
[INFO] | +- com.google.appengine.orm:datanucleus-appengine:jar:1.0.10:runtime
[INFO] | \- com.google.appengine:appengine-tools-sdk:jar:1.7.2:compile
[INFO] +- com.google.appengine:appengine-api-labs:jar:1.7.2:test
[INFO] +- com.google.appengine:appengine-api-stubs:jar:1.7.2:test
[INFO] +- com.google.appengine:appengine-testing:jar:1.7.2:test
[INFO] +- com.google.api-client:google-api-client-appengine:jar:1.10.3-beta:compile
[INFO] | +- com.google.oauth-client:google-oauth-client-appengine:jar:1.10.1-beta:compile
[INFO] | | +- com.google.oauth-client:google-oauth-client-servlet:jar:1.10.1-beta:compile
[INFO] | +- com.google.api-client:google-api-client-servlet:jar:1.10.3-beta:compile
[INFO] | \- com.google.http-client:google-http-client-appengine:jar:1.10.3-beta:compile
[INFO] | \- com.google.http-client:google-http-client:jar:1.10.3-beta:compile
[INFO] | +- com.google.code.gson:gson:jar:2.1:compile
[INFO] | \- com.google.protobuf:protobuf-java:jar:2.2.0:compile
知道我错过了什么或做错了吗?
答案 0 :(得分:1)
我只是通过添加以下依赖项来重现此错误并修复它:
<!--
GAE libraries for local testing as described here:
http://code.google.com/appengine/docs/java/howto/unittesting.html
-->
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-labs</artifactId>
<version>${gae.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-stubs</artifactId>
<version>${gae.version}</version>
<scope>test</scope>
</dependency>
我使用本地maven属性来引用相同的gae版本
希望这个帮助
此致