【问题标题】:Maven test fail on terminal but passes in IntelliJMaven 测试在终端上失败,但在 IntelliJ 中通过
【发布时间】:2019-10-25 20:57:11
【问题描述】:

我的 Spring Boot 应用程序使用 TestNG 并且它具有 surefire 插件。我试图将它打包在终端上,但它在 Maven 测试步骤中一直失败。如果我在 IntelliJ 上运行 maven package 命令,所有 maven 步骤都运行良好并通过。

当它尝试在终端/命令行上mvn test 时,我只会收到如下错误。会是什么呢?我认为这是一个 Mockito 依赖问题,但即使在我的 pom.xml 中添加它之后也没有任何改变。

You can learn about inline mocks and their limitations under item #39 of the Mockito class javadoc.

Underlying exception : org.mockito.exceptions.base.MockitoException: Could not modify all classes [class java.lang.Object, class org.fluentd.logger.FluentLogger]
    at com.homedepot.appconfig.error.reporting.StackDriverErrorReporterTest.reportError_WithHttpRequest_False(StackDriverErrorReporterTest.java:112)
Caused by: org.mockito.exceptions.base.MockitoException: Could not modify all classes [class java.lang.Object, class org.fluentd.logger.FluentLogger]
    at com.homedepot.appconfig.error.reporting.StackDriverErrorReporterTest.reportError_WithHttpRequest_False(StackDriverErrorReporterTest.java:112)
Caused by: java.lang.IllegalStateException: 

Byte Buddy could not instrument all classes within the mock's type hierarchy

This problem should never occur for javac-compiled classes. This problem has been observed for classes that are:
 - Compiled by older versions of scalac
 - Classes that are part of the Android distribution
    at com.homedepot.appconfig.error.reporting.StackDriverErrorReporterTest.reportError_WithHttpRequest_False(StackDriverErrorReporterTest.java:112)
Caused by: java.lang.IllegalArgumentException
    at com.homedepot.appconfig.error.reporting.StackDriverErrorReporterTest.reportError_WithHttpRequest_False(StackDriverErrorReporterTest.java:112)
Mockito cannot mock this class:```


【问题讨论】:

  • 请点击此链接并编辑您的问题。 stackoverflow.com/help/minimal-reproducible-example
  • @DavidLe 你能解决这个问题吗?我遇到了完全相同的问题。我正在使用 jdk 11、junit juniper 5.3.2、mockito-junit-jupiter 2.24.0 和 mockito-core 2.24.4。当我在 IntelliJ 中运行时我的测试通过并在终端上失败并出现您遇到的错误。

标签: java maven intellij-idea


【解决方案1】:

检查它选择运行测试的 maven 版本和 pom.xml 文件;这是我的疯狂猜测。

【讨论】:

  • 所以使用mvn -version 我得到Apache Maven 3.6.0 但查看pom.xml 我看到3.8.0maven-compiler-plugin 这可能是不匹配问题吗?
【解决方案2】:

在我的情况下,maven-surefire-pluginpom.xml<build> 部分中丢失。添加插件:

<build>
       <plugins>
           <plugin>
               <artifactId>maven-surefire-plugin</artifactId>
               <version>your-version</version>
           </plugin>
       </plugins>

<!--        other plugins ...-->

 </build>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-13
    • 2014-03-08
    • 2020-09-21
    • 2011-03-22
    • 2017-05-26
    • 2019-07-31
    • 2016-05-17
    • 1970-01-01
    相关资源
    最近更新 更多