I am trying to unit test my app engine endpoint api. I am following the example from udacity. They seem to be using a LocalServiceTestHelper
but I struggle to understand why, since it is not used later in the code.
Here is my backend gradle file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.google.appengine:gradle-appengine-plugin:1.9.28'
}
}
repositories {
jcenter();
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
dependencies {
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.28'
compile 'com.google.appengine:appengine-endpoints:1.9.28'
compile 'com.google.appengine:appengine-endpoints-deps:1.9.28'
compile 'javax.servlet:servlet-api:2.5'
compile 'com.googlecode.objectify:objectify:5.0.3'
compile 'javax.jdo:jdo-api:3.0.1'
compile 'junit:junit:4.12'
compile 'com.google.appengine:appengine-testing:1.9.24'
}
appengine {
downloadSdk = true
appcfg {
oauth2 = true
}
endpoints {
getClientLibsOnBuild = true
getDiscoveryDocsOnBuild = true
}
}
Here is the Endpoint test class (the import statements and other trivial details have been omitted for conciseness):
private final LocalServiceTestHelper helper =
new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig()
.setDefaultHighRepJobPolicyUnappliedJobPercentage(100));
/**
* Set up the local service tester before running tests and an instance of the magpieApi.
* @throws Exception
*/
@Before
public void setUp() throws Exception {
//helper.setUp();
user = new User(EMAIL, "gmail.com" ,USER_ID);
magpieApi = new MagpieEndpoint();
}
/**
* After running tests clear objectify and tear down the local test helper.
* @throws Exception
*/
@After
public void tearDown() throws Exception {
ofy().clear();
helper.tearDown();
}
Here is important part of the error log:
java.lang.NoClassDefFoundError: com/google/appengine/api/datastore/dev/LocalDatastoreService$AutoIdAllocationPolicy
at com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig.<init>(LocalDatastoreServiceTestConfig.java:24)
at test.MagpieEndpointTest.<init>(MagpieEndpointTest.java:54)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:217)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.lang.ClassNotFoundException: com.google.appengine.api.datastore.dev.LocalDatastoreService$AutoIdAllocationPolicy
I am new to google app engine and have never unit tested my code before, so please be nice (only 16 years old). There are no syntax errors so I am curious as to what is causing the issue. Line 54 is obviously the source of the problem, which is where I initiate and declare the helper
variable.
Thank you.
Aucun commentaire:
Enregistrer un commentaire