PowerMock Throwing an Exception from @RunWith(PowerMockRunner.class) Annotation?

Looks like I was adding PowerMock to the build incorrectly. When I looked through the problems view in Eclipse, I found the following.

Up vote 1 down vote favorite share g+ share fb share tw.

I'm trying to get PowerMockito working with my application. I've added the library to the build path. I have the following test class: 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() { } } When I try to run the tests, I get the following exception: 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.(PowerMockRunner.

Java:24) at sun.reflect. NativeConstructorAccessorImpl. NewInstance0(Native Method) at sun.reflect.

NativeConstructorAccessorImpl. NewInstance(NativeConstructorAccessorImpl. Java:39) at sun.reflect.

DelegatingConstructorAccessorImpl. NewInstance(DelegatingConstructorAccessorImpl. Java:27) at java.lang.reflect.Constructor.

NewInstance(Constructor. Java:513) at org.junit.internal.builders. AnnotatedBuilder.

BuildRunner(AnnotatedBuilder. Java:31) at org.junit.internal.builders. AnnotatedBuilder.

RunnerForClass(AnnotatedBuilder. Java:24) at org.junit.runners.model.RunnerBuilder. SafeRunnerForClass(RunnerBuilder.

Java:57) at org.junit.internal.builders. AllDefaultPossibilitiesBuilder. RunnerForClass(AllDefaultPossibilitiesBuilder.

Java:29) at org.junit.runners.model.RunnerBuilder. SafeRunnerForClass(RunnerBuilder. Java:57) at org.junit.internal.requests.ClassRequest.

GetRunner(ClassRequest. Java:24) at org.eclipse.jdt.internal. Junit4.runner.

JUnit4TestReference.(JUnit4TestReference. Java:33) at org.eclipse.jdt.internal. Junit4.runner.

JUnit4TestClassReference.(JUnit4TestClassReference. Java:25) at org.eclipse.jdt.internal. Junit4.runner.

JUnit4TestLoader. CreateTest(JUnit4TestLoader. Java:48) at org.eclipse.jdt.internal.

Junit4.runner. JUnit4TestLoader. LoadTests(JUnit4TestLoader.

Java:38) at org.eclipse.jdt.internal.junit.runner. RemoteTestRunner. RunTests(RemoteTestRunner.

Java:452) at org.eclipse.jdt.internal.junit.runner. RemoteTestRunner. RunTests(RemoteTestRunner.

Java:683) at org.eclipse.jdt.internal.junit.runner. RemoteTestRunner. Run(RemoteTestRunner.

Java:390) at org.eclipse.jdt.internal.junit.runner. RemoteTestRunner. Main(RemoteTestRunner.

Java:197) Caused by: java.lang. ClassNotFoundException: org.junit.internal.runners. TestClassRunner at java.net.

URLClassLoader$1. Run(URLClassLoader. Java:202) 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) ... 31 more According to the PowerMock FAQ, I should try using the legacy package. I did, and I'm still getting the same exception.

Any ideas? Java junit jar mockito powermock link|improve this question asked Mar 4 at 7:46helixed1,3261725 94% accept rate.

1 Is the JAR that contains org.junit.internal.runners. TestClassRunner on the classpath? – David Harkness Mar 4 at 8:11 It appears to have been removed/renamed in JUnit 4.5 and possibly earlier.

– David Harkness Mar 4 at 8:16 I'm using JUnit 4.8.2. How do I check the class path? If I try to import that package, Eclipse tells me it cannot be resolved.

– helixed Mar 4 at 8:47 When looking at the PowerMock FAQ, it mentioned the legacy package for use with JUnit 3. Are you sure you're supposed to be using it? – David Harkness Mar 4 at 10:06 1 Also you can't mock System methods like that as it is in rt.

Jar, i.e. It is a system class. Here's how you should proceed : code.google.com/p/powermock/wiki/MockSystem – Brice Mar 4 at 10:57.

Looks like I was adding PowerMock to the build incorrectly. When I looked through the problems view in Eclipse, I found the following: Archive 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 Removing these two files from the build path fixed the problem.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions