我正在努力让PowerMockito使用我的应用程序.我已将库添加到构建路径中.我有以下测试类:
package client.controller;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
@PrepareForTest(System.class)
public class SampleTest
{
@Test
public void test()
{
}
}
当我尝试运行测试时,我得到以下异常:
java.lang.NoClassDefFoundError: org/junit/internal/runners/TestClassRunner
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at org.powermock.modules.junit4.legacy.PowerMockRunner.301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 31 more
根据PowerMock FAQ,我应该尝试使用旧版程序包.我做了,我仍然得到同样的例外.有任何想法吗?
最佳答案
看起来我正在错误地将PowerMock添加到构建中.当我查看Eclipse中的问题视图时,我发现了以下内容:
原文链接:https://www.f2er.com/java/438030.htmlArchive for required library: 'lib/powermock-mockito-junit-1.4.11 4/powermock-release-junit-without-mock-framework-1.4.11.pom' in project 'Test' cannot be read or is not a valid ZIP file Test Build path Build Path Problem
Archive for required library: 'lib/powermock-mockito-junit-1.4.11 4/powermock-release-without-test-and-mock-framework-1.4.11.pom' in project 'Test' cannot be read or is not a valid ZIP file Test Build path Build Path Problem