简单的PowerMock测试给出了一个错误,即Android Studio项目



我在Android Studio中有一个项目。我想通过Mockito和PowerMock框架测试一些功能。PowerMock在简单测试中给出了初始Zaton错误:

@RunWith(PowerMockRunner.class)
@PrepareForTest( {RawDataAmFmFrequency.class} )
public class TestRawDataAmFmFrequency {
  @Test
  public void TestEx() {
  }

我得到错误:

java.lang.NoClassDefFoundError: org/powermock/reflect/proxyframework/ClassLoaderRegisterProxyFramework
    at org.powermock.tests.utils.impl.AbstractCommonTestSuiteChunkerImpl.registerProxyframework(AbstractCommonTestSuiteChunkerImpl.java:101)
    at org.powermock.tests.utils.impl.AbstractCommonTestSuiteChunkerImpl.chunkClass(AbstractCommonTestSuiteChunkerImpl.java:114)
    at org.powermock.tests.utils.impl.AbstractCommonTestSuiteChunkerImpl.<init>(AbstractCommonTestSuiteChunkerImpl.java:60)
    at org.powermock.tests.utils.impl.AbstractCommonTestSuiteChunkerImpl.<init>(AbstractCommonTestSuiteChunkerImpl.java:54)
    at org.powermock.tests.utils.impl.AbstractTestSuiteChunkerImpl.<init>(AbstractTestSuiteChunkerImpl.java:58)
    at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.<init>(JUnit4TestSuiteChunkerImpl.java:59)
    at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.<init>(AbstractCommonPowerMockRunner.java:32)
    at org.powermock.modules.junit4.PowerMockRunner.<init>(PowerMockRunner.java:34)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:98)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
    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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.lang.ClassNotFoundException: org.powermock.reflect.proxyframework.ClassLoaderRegisterProxyFramework
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

我已经检查了我的依赖项的版本:

testCompile files('libs/mockito-all-2.0.2-beta.jar')
testCompile files('libs/mockito-core-2.0.5-beta.jar')
testCompile files('libs/powermock-api-mockito-1.6.5.jar')
testCompile files('libs/powermock-api-mockito-common-1.6.5.jar')
testCompile files('libs/powermock-core-1.6.5.jar')
testCompile files('libs/powermock-module-junit4-1.6.5.jar')
testCompile files('libs/powermock-module-junit4-common-1.6.5.jar')
testCompile files('libs/powermock-api-support-1.6.5.jar')
testCompile files('libs/javassist-3.14.0-ga-1.0.0.jar')
testCompile files('libs/cglib-2.2.2.jar')

Mockito效果很好,但是PowerMock仍然有一个错误。

请帮助

我添加了另一种依赖性: testCompile files('libs/powermock-reflect-1.6.5.jar')

我还将javassist的版本更改为:testCompile files('libs/javassist-3.18.2-GA.jar')

它解决了我的问题。

相关内容

  • 没有找到相关文章

最新更新