简体   繁体   English

Google App Engine数据存储单元使用Maven进行测试

[英]Google App Engine Data Store Unit Tests With Maven

Trying to get my GAE 1.9.0 project's unit tests to run using maven 3.2.1. 试图让我的GAE 1.9.0项目的单元测试使用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. 似乎无法找到有关如何正确配置数据存储区测试的pom.xml的文档。 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/maven#junit_dependencies_optional

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

the test dependencies in my pom.xml 我的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)

In my case, adding testCompile 'com.google.appengine:appengine-tools-sdk:1.9.24' to my build.gradle fixed it. 在我的例子中,将testCompile 'com.google.appengine:appengine-tools-sdk:1.9.24'到我的build.gradle中修复它。 (I'm using gradle - the maven equivalent should be the same.) Here are my test dependencies: (我正在使用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'

I don't know what changed - it used to work without that dependency. 我不知道发生了什么变化 - 它曾经没有那种依赖性。 But at least that seams to solve the problem. 但至少可以解决这个问题。

我不知道你们是否解决了,但是使用GAE版本1.8.2对我有用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为Google App Engine单元测试设置已经一致的数据? - How to set up already consistent data for Google App Engine unit tests? 如何使用Google App Engine插件从WAR中排除单元测试? - How to exclude unit tests from the WAR in with Google App Engine plugin? 在同一应用程序中使用Google Data Store和Google App Engine - Use Google Data Store and Google App Engine in same application 单元测试App引擎-Eclipse-Maven - Unit testing App engine - Eclipse - Maven Google应用引擎的gradle单元测试在哪里需要persistence.xml? - Where do gradle unit tests for Google app engine expect persistence.xml? 在Java版本的Google App Engine中,您如何评估和执行以字符串形式传入的Java代码和单元测试? - In the Java version of Google App Engine, how can you eval and execute Java code and unit tests passed in as strings? 在谷歌应用引擎数据存储中更新查询(java) - Update query in google app engine data store (java) 使用Google App Engine按数据存储中的时间列排序 - sorting by time column in data store using google app engine 在Google App Engine上存储和返回数据的最简单方法 - Simplest way to store and return data on google app engine 如何部分更新Google App Engine数据存储中的实体 - How to Update an Entity in a Google app engine data store partially
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM