【问题标题】:Github - Google pubsub java samples - Maven test run failureGithub - Google pubsub java 示例 - Maven 测试运行失败
【发布时间】:2016-08-29 09:10:31
【问题描述】:

我正在尝试通过参考this 指南在本地开发服务器上运行 Google pubsub java 示例 - appengine 推送。

$ gcloud config set project <provided-my-application-id>
$ mvn gcloud:run

Maven 构建成功,但测试运行失败。下面是执行。如何解决?

E:\java\cloud-pubsub-samples-java-master\appengine-push>mvn gcloud:run
[INFO] Scanning for projects...
[WARNING] The POM for com.google.appengine:appengine-maven-plugin:jar:2.0.9.121.v20160815 is missing, no dependency information available
[WARNING] Failed to retrieve plugin descriptor for com.google.appengine:appengine-maven-plugin:2.0.9.121.v20160815: Plugin com.google.appengine:appengine-maven-plugin:2.0.9.121.v20160815 or one of its dependencies could not be resolved: Failure to find com.google.appengine:appengine-maven-plugin:jar:2.0.9.121.v20160815 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Example for the Google Cloud Pub/Sub on Google App Engine. 1
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for com.google.appengine:appengine-maven-plugin:jar:2.0.9.121.v20160815 is missing, no dependency information available
[WARNING] Failed to retrieve plugin descriptor for com.google.appengine:appengine-maven-plugin:2.0.9.121.v20160815: Plugin com.google.appengine:appengine-maven-plugin:2.0.9.121.v20160815 or one of its dependencies could not be resolved: Failure to find com.google.appengine:appengine-maven-plugin:jar:2.0.9.121.v20160815 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced
[INFO]
[INFO] >>> gcloud-maven-plugin:2.0.9.90.v20151210:run (default-cli) > package @ pubsub-appengine-sample >>>
[INFO]
[INFO] --- maven-checkstyle-plugin:2.15:check (validate) @ pubsub-appengine-sample ---
[INFO] Starting audit...
Audit done.
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ pubsub-appengine-sample ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory E:\java\cloud-pubsub-samples-java-master\appengine-push\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ pubsub-appengine-sample ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 10 source files to E:\java\cloud-pubsub-samples-java-master\appengine-push\target\war\WEB-INF\classes
[INFO]
[INFO] --- versions-maven-plugin:2.2:display-dependency-updates (default) @ pubsub-appengine-sample ---
[INFO] artifact com.google.api-client:google-api-client-appengine: checking for updates from central
[INFO] artifact com.google.appengine:appengine-api-1.0-sdk: checking for updates from central
[INFO] artifact junit:junit: checking for updates from central
[INFO] artifact org.codehaus.jackson:jackson-mapper-asl: checking for updates from central
[INFO] artifact com.google.apis:google-api-services-pubsub: checking for updates from central
[INFO] artifact org.mockito:mockito-all: checking for updates from central
[INFO] The following dependencies in Dependencies have newer versions:
[INFO]   com.google.api-client:google-api-client-appengine ... 1.21.0 -> 1.22.0
[INFO]   com.google.apis:google-api-services-pubsub ...
[INFO]                                        v1-rev8-1.21.0 -> v1-rev11-1.22.0
[INFO]   com.google.appengine:appengine-api-1.0-sdk .......... 1.9.31 -> 1.9.42
[INFO]   org.mockito:mockito-all ........................ 1.10.19 -> 2.0.2-beta
[INFO]
[INFO]
[INFO] --- versions-maven-plugin:2.2:display-plugin-updates (default) @ pubsub-appengine-sample ---
[INFO]
[INFO] The following plugin updates are available:
[INFO]   com.google.appengine:gcloud-maven-plugin  2.0.9.90.v20151210 -> 2.0.9.121.v20160815
[INFO]   maven-checkstyle-plugin ................................ 2.15 -> 2.17
[INFO]   maven-compiler-plugin .................................. 3.3 -> 3.5.1
[INFO]   org.codehaus.mojo:findbugs-maven-plugin .............. 3.0.3 -> 3.0.4
[INFO]   org.codehaus.mojo:versions-maven-plugin .................. 2.2 -> 2.3
[INFO]
[WARNING] The following plugins do not have their version specified:
[WARNING]   maven-clean-plugin ........................ (from super-pom) 3.0.0
[WARNING]   maven-deploy-plugin ....................... (from super-pom) 2.8.2
[WARNING]   maven-install-plugin ...................... (from super-pom) 2.5.2
[WARNING]   maven-resources-plugin .................... (from super-pom) 3.0.1
[WARNING]   maven-site-plugin ......................... (from super-pom) 3.5.1
[WARNING]   maven-surefire-plugin .................... (from super-pom) 2.19.1
[INFO]
[INFO] Project defines minimum Maven version as: 3.1.0
[INFO] Plugins require minimum Maven version of: 3.1.0
[INFO] Note: the super-pom from Maven 3.3.9 defines some of the plugin
[INFO]       versions and may be influencing the plugins required minimum Maven
[INFO]       version.
[INFO]
[INFO] No plugins require a newer version of Maven than specified by the pom.
[INFO]
[INFO]
[INFO] --- maven-war-plugin:2.6:exploded (default) @ pubsub-appengine-sample ---
[INFO] Exploding webapp
[INFO] Assembling webapp [pubsub-appengine-sample] in [E:\java\cloud-pubsub-samples-java-master\appengine-push\target\war]
[INFO] Processing war project
[INFO] Copying webapp resources [E:\java\cloud-pubsub-samples-java-master\appengine-push\src\main\webapp]
[INFO] Webapp assembled in [859 msecs]
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ pubsub-appengine-sample ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory E:\java\cloud-pubsub-samples-java-master\appengine-push\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.3:testCompile (default-testCompile) @ pubsub-appengine-sample ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ pubsub-appengine-sample ---
[INFO] Surefire report directory: E:\java\cloud-pubsub-samples-java-master\appengine-push\target\surefire-reports

-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.google.cloud.pubsub.client.demos.appengine.IntegrationTest
Tests run: 3, Failures: 3, Errors: 0, Skipped: 0, Time elapsed: 2.351 sec <<< FAILURE!
testTopPage(com.google.cloud.pubsub.client.demos.appengine.IntegrationTest)                Time elapsed: 1.442 sec  <<< FAILURE!
java.lang.AssertionError: expected:<200> but was:<404>
    at org.junit.Assert.fail(Assert.java:88)
    at org.junit.Assert.failNotEquals(Assert.java:834)
    at org.junit.Assert.assertEquals(Assert.java:645)
    at org.junit.Assert.assertEquals(Assert.java:631)
    at com.google.cloud.pubsub.client.demos.appengine.IntegrationTest.testTopPage(IntegrationTest.java:72)
    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 org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    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.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:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    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)

   testSendMessage(com.google.cloud.pubsub.client.demos.appengine.IntegrationTest)       Time elapsed: 0.369 sec  <<< FAILURE!
java.lang.AssertionError: expected:<204> but was:<404>
    at org.junit.Assert.fail(Assert.java:88)
    at org.junit.Assert.failNotEquals(Assert.java:834)
    at org.junit.Assert.assertEquals(Assert.java:645)
    at org.junit.Assert.assertEquals(Assert.java:631)
    at com.google.cloud.pubsub.client.demos.appengine.IntegrationTest.testSendMessage(IntegrationTest.java:151)
    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 org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    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.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:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    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)

testPushHandlerIsProtected(com.google.cloud.pubsub.client.demos.appengine.IntegrationTest)  Time elapsed: 0.336 sec  <<< FAILURE!
java.lang.AssertionError: expected:<302> but was:<404>
    at org.junit.Assert.fail(Assert.java:88)
    at org.junit.Assert.failNotEquals(Assert.java:834)
    at org.junit.Assert.assertEquals(Assert.java:645)
    at org.junit.Assert.assertEquals(Assert.java:631)
    at com.google.cloud.pubsub.client.demos.appengine.IntegrationTest.testPushHandlerIsProtected(IntegrationTest.java:128)
    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 org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    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.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:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    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)


Results :

Failed tests:        testTopPage(com.google.cloud.pubsub.client.demos.appengine.IntegrationTest): expected:<200> but was:<404>
   testSendMessage(com.google.cloud.pubsub.client.demos.appengine.IntegrationTest): expected:<204> but was:<404>
  testPushHandlerIsProtected(com.google.cloud.pubsub.client.demos.appengine.IntegrationTest): expected:<302> but was:<404>

Tests run: 3, Failures: 3, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 23.681 s
[INFO] Finished at: 2016-08-29T08:28:48+05:30
[INFO] Final Memory: 31M/333M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire- plugin:2.12.4:test (default-test) on project pubsub-appengine-sample: There are test failures.
[ERROR]
[ERROR] Please refer to E:\java\cloud-pubsub-samples-java-master\appengine-push\target\surefire-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1]      http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

更新 - 测试运行失败观察: 我的观察是, 对于 testTopPage() - 第 72 行通过,响应为 200。但在第 84 行失败,因为内容没有我的项目 _id。

对于 testSendMessage() - 在第 133 行失败,出现 404 错误,url = getAppBaseURL() + "send_message";因为没有这样的资源。

同样,testPushHandlerIsProtected()- 在第 110 行失败并出现 404 错误,因为没有这样的资源。

注意:我的项目在 appengine 中只有 hello world 应用程序,但这些测试方法正在寻找 appengine 中不存在的资源。我错过了什么?

【问题讨论】:

  • 您必须在 appengine 上部署示例应用程序才能进行测试(请参阅我的答案的编辑)。

标签: java google-app-engine google-cloud-pubsub


【解决方案1】:

查看第 31 行 in the test。它使用称为“TEST_PROJECT_ID”的不同环境变量(参见第 24 行)。它应该像设置正确的环境变量一样简单。您还可以在单​​元测试中为 URL 添加调试输出,以便了解使用的主机名。

Edit1:你的意思是,你在 appengine 中只有一个 hello world 应用程序? 'send_message' 资源和 init_servlet(它返回第 84 行断言的项目 ID)在示例的 web.xml 中定义。您必须先部署此应用程序,然后再针对它运行测试(或找到该应用程序的一个已在运行的实例)。如果由于测试失败而无法部署应用程序,则可以通过将 -DskipTests 参数添加到 maven 命令来跳过安全测试。这也解释了in the readme of the project

【讨论】:

  • 环境变量按预期提供。我的观察结果是,对于 testTopPage() - 第 72 行,响应代码为 200,符合预期。但在第 84 行失败,因为内容没有我的项目 _id。对于 testSendMessage() - 在第 133 行失败,出现 404 错误,url = getAppBaseURL() + "send_message";因为没有这样的资源。对于 testPushHandlerIsProtected() - 在第 110 行失败并出现 404 错误,因为没有这样的资源。这些测试方法正在寻找 appengine 中不存在的资源。我错过了什么?如何完成这项工作?
  • 用测试运行失败观察更新了问题。
  • 是的。我在部署项目时遇到了一些困难。发布了一个单独的问题来解决这里部署时遇到的错误 - stackoverflow.com/questions/39234400/…
猜你喜欢
  • 1970-01-01
  • 2021-02-19
  • 1970-01-01
  • 2021-04-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多