gpt4 book ai didi

java - 当存在对mockito-core的依赖时,测试不会运行

转载 作者:行者123 更新时间:2023-12-01 19:55:51 25 4
gpt4 key购买 nike

我已将 mockito-core 添加到我的依赖项中,但我似乎无法运行测试(运行时出错),除非我还添加 powermock-api-mockito到依赖项。在放入 mockito-core 依赖项后,我立即开始收到错误 - 不需要其他更改(例如,我不需要添加使用 Mockito 开始看到错误的代码)。

我要添加的依赖项:

  <dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>

我似乎需要包含依赖项:

<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.6.5</version>
<scope>test</scope>
</dependency>

如果没有上述第二个依赖项,我会收到以下错误。再次强调,这纯粹是依赖项更改,没有代码更改:

java.lang.NoClassDefFoundError: org/hamcrest/TypeSafeMatcher

at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)

还有这个:

java.lang.NoClassDefFoundError: org/junit/internal/matchers/StacktracePrintingMatcher

at org.junit.matchers.JUnitMatchers.isThrowable(JUnitMatchers.java:103)
at org.junit.rules.ExpectedExceptionMatcherBuilder.build(ExpectedExceptionMatcherBuilder.java:27)
at org.junit.rules.ExpectedException.handleException(ExpectedException.java:252)
at org.junit.rules.ExpectedException.access$000(ExpectedException.java:106)
at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:241)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
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.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

最佳答案

这应该通过使用mockito-all而不是mockito-core来解决。它将具有mockito所需的所有依赖项。 hamcrest 和 junit 是其中的一部分。

关于java - 当存在对mockito-core的依赖时,测试不会运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49792198/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com