When I try to Spy an object in my unit test, I got an exception. This is my unit test file:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loc
It might be problem with the dependencies. The powermock-api-mockito
has compile time dependency on mockito-core
version 1.10.19
, but you have also defined a dependency on version 2.0.44-beta
. This might be a classpath problem. Try removing the explicit dependency on version 2.0.44-beta
.
This is happening because of the dependency of powermock-api-mockito on mockito-core . Since powermock-api-mockito is added explicitly as dependency please remove mockito-core, this might be causing the issue
Use powermock-api-mockito2
if you are using 2.x.x version of mockito-core
as powermock-api-mockito
is not compatible with mockito-core 2
.
In the release 2.0.32-beta Mockito team moved cglib classes into separated jar. But PowerMock still depends on classes which have been moved, so you get java.lang.NoClassDefFoundError.
In release 1.6.2 Mockito classes was copied into PowerMock, but not all. As workaround I may suggest clone, build and add to classpath the mockito-cglib (https://github.com/mockito/mockito-cglib).
The PowerMock will have supported Mockito 2 API since 1.6.5 which will have been released by the end of the May, but will still use cglib. The full Mockito 2 with Bytebuddy will be supported in release after 1.6.5.
Developer Guide for Migration to Mockito 2