Matt Matt - 18 days ago 9
Java Question

PowerMock NoClassDefFoundError

I have some simple classes I'm using to see if I can get

powermock
to work:

import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

@RunWith(PowerMockRunner.class)
@PrepareForTest(Foo.class)
public class FooTest
{
@Test
public void testFoobar(){
Foo test = PowerMock.createPartialMock(Foo.class, "foobar");
PowerMock.replay(test);
}
}


and

public class Foo
{
public String foobar(String aString){
return aString + " blah";
}
}


When I try to run this unit test, it tells me:

java.lang.NoClassDefFoundError: org/easymock/classextension/internal/ClassProxyFactory$MockMethodInterceptor
...


I have no idea why its doing this. Please help.

Answer

Make sure you're including EasyMock in your class path when using PowerMock... you can find the download page here.

According to the Wiki on PowerMock, it states that EasyMock is a dependency.

Comments