When I mock objects in Junit test cases using of PowerMock and Mockito, I'm getting this exception:
java.lang.NoClassDefFoundError: org/mockito/exceptions/base/MockitoSerializationIssue
Mock objects is a unit testing technique in which a code chunk is replaced by dummy implementations that emulate real code. This helps one to write unit tests targeting the functionality provided by the class under test.
initMocks(Object) is not necessary. Mocks are initialized before each test method.
Mock objects can be initialized using Mockito annotation @Mock and MockitoAnnotations#initMocks(Object) . Pros: Declarative thanks to @Mock annotation.
Mockito verify() method can be used to test number of method invocations too. We can test exact number of times, at least once, at least, at most number of invocation times for a mocked method. We can use verifyNoMoreInteractions() after all the verify() method calls to make sure everything is verified.
I got this when combining PowerMock with Mockito. Fixed by using compatible version as shown here: https://github.com/powermock/powermock/wiki/Mockito#supported-versions
Check version of your mockito lib. I see org.mockito.exceptions.base.MockitoSerializationIssue class in 2.0.2-beta. It is not present in 1.9.5 .
You don't have to use the beta version. The latest 1.10.x should also work. I had the same problem when using 1.9.5, but changing to 1.10.19 fixed the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With