Question

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)
Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top