8

Trying to get my GAE 1.9.0 project's unit tests to run using maven 3.2.1. Data Store Related Tests Fail :

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

I understand this means i'm missing a dependency. Can't seem to find a doc on how to properly configure my pom.xml for datastore tests. The test crashes when I call

helper.setup()

on the helper:

public final LocalServiceTestHelper helper = new LocalServiceTestHelper(
            new LocalDatastoreServiceTestConfig(),
            new LocalTaskQueueTestConfig(),
            new LocalBlobstoreServiceTestConfig(),
            new LocalUserServiceTestConfig()));

referenced:

https://developers.google.com/appengine/docs/java/tools/maven#junit_dependencies_optional

https://developers.google.com/appengine/docs/java/tools/localunittesting#Java_Writing_Datastore_and_memcache_tests

the test dependencies in my 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>

rest of the stack trace:

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)
bsautner
  • 4,479
  • 1
  • 36
  • 50
  • no sorry - i'm running integration tests against a sql db and migrating my db related tests off gae. – bsautner Mar 28 '14 at 18:07
  • I had to do the same thing.. basically i just added the dependencies mentioned in the https://developers.google.com/appengine/docs/java/tools/maven#junit_dependencies_optional section "Configuring pom.xml settings for Google App Engine" and it worked – Madhan Ganesh May 11 '14 at 22:19
  • I have the exact same problem. I tried copying the pom entries from the GAE site to no avail. Running local TestNG tests thru eclipse works fine. It's only when running thru maven I see this. – Ryan Reynolds May 28 '14 at 23:55
  • do let me know if you come up with a fix Ryan, i'm still not past this issue. I don't know if Madhan's comment works for datastore tests. – bsautner May 29 '14 at 15:20

2 Answers2

3

In my case, adding testCompile 'com.google.appengine:appengine-tools-sdk:1.9.24' to my build.gradle fixed it. (I'm using gradle - the maven equivalent should be the same.) Here are my test dependencies:

// 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'

I don't know what changed - it used to work without that dependency. But at least that seams to solve the problem.

Tad
  • 4,668
  • 34
  • 35
0

I don't know if you guys solved, but using the GAE version 1.8.2 worked for me !

Leonardo
  • 3,141
  • 3
  • 31
  • 60