I’m using the Mockito library for Java testing and getting errors in Mockito when I run my test. (I’m using the NetBeans IDE, in case that’s relevant). For example, I have a class called Animal and I am trying to perform the following simple test:
@Test
public void mokito_test(){
Animal mockAnimal = mock(Animal.class);
Animal testAnimal2 = mockAnimal;
assertTrue(mockAnimal.equals(testAnimal2));
}
This test gives the following error:
mokito_test caused an ERROR (at org.mockito.internal.creation.jmock.ClassImposterizer.<init>(ClassImposterizer.java:37))
at org.mockito.internal.creation.jmock.ClassImposterizer.<init>(ClassImposterizer.java:37)
at org.mockito.internal.util.CreationValidator.validateType(CreationValidator.java:14)
at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:33)
...etc.
(There are 11 more errors, including in java.net, java.security, java.lang, and sun.misc.)
However, if I perform this test using a real object instead of a mocked object, the test is successfull:
@Test
public void animal_test(){
Animal testAnimal1 = new Animal("bear");
Animal testAnimal2 = new Animal("bear");
assertTrue(testAnimal1.equals(testAnimal2));
}
This test is successfull.
I have downloaded the Mockito jar file (mockito-core-1.8.0.jar) into my project directory, and then referencing the relative path of the jar file in the testing library for this particular project. I’ve never used Mockito before, so I suspect that my error has something to do with my system configuration. Any help would be greatly appreciated! Thanks!
Mockito has some external dependencies on
objenesisandhamcrestlibraryes, line 37 attempts to construct an object fromobjensislibrary.Please use mockito-all-1.8.jar instead.