Re: [mockito] Setting up Mockito in Intellij Idea

4,188 views
Skip to first unread message

Brice Dutheil

unread,
Aug 24, 2012, 4:57:26 AM8/24/12
to moc...@googlegroups.com
Hi,

You have a class path issue. The stack trace is telling you that the class org.objenesis.ObjenesisStd is missing.
As you used the mockito-core jar, you need to put in the classpath additional dependencies, such as Objenesis and Hamcrest.

Cheers,

-- Brice Dutheil

On Wednesday, August 22, 2012 at 9:47 PM, Apurva wrote:

I am trying to use Mockito in my android project that I have set up in Intellij Idea 11.1.3. I copied the mockito-core-1.9.5-rc1.jar and dexmaker-20120622.jar in the libs folder of my test module. Then I included these jars as dependencies in test module. Here is the test I wrote:

    @Test
    public void testGetPlannedIncidentData() throws Exception {
        FileParser mockFileParser= mock(FileParser.class);
        when(mockFileParser.readFile("Test")).thenReturn("hh");

        MODataManager moDataManager=new MODataManager();
         moDataManager.fileParser = mockFileParser;
        List<MOPlannedIncidentData> data=moDataManager.getPlannedIncidentData() ;

        //verify(mockFileParser).readFile((anyString()));
        assertTrue(data!=null);
        assertTrue(data!=null);
    }

However when I try running test I get an error message saying-
java.lang.ExceptionInInitializerError
at org.mockito.internal.util.MockCreationValidator.isTypeMockable(MockCreationValidator.java:17)
at org.mockito.internal.util.MockCreationValidator.validateType(MockCreationValidator.java:21)
at org.mockito.internal.creation.MockSettingsImpl.validatedSettings(MockSettingsImpl.java:133)
at org.mockito.internal.creation.MockSettingsImpl.confirm(MockSettingsImpl.java:127)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:50)
at org.mockito.Mockito.mock(Mockito.java:1243)
at org.mockito.Mockito.mock(Mockito.java:1120)
at gov.mo.dot.timm.model.MODataManagerTest.testGetPlannedIncidentData(MODataManagerTest.java:41)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:204)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:194)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:529)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1584)
Caused by: java.lang.NoClassDefFoundError: org.objenesis.ObjenesisStd
at org.mockito.internal.creation.jmock.ClassImposterizer.<init>(ClassImposterizer.java:36)
at org.mockito.internal.creation.jmock.ClassImposterizer.<clinit>(ClassImposterizer.java:29)
... 21 more

Any help is highly appreciated.

Thanks

--
You received this message because you are subscribed to the Google Groups "mockito" group.
To view this discussion on the web visit https://groups.google.com/d/msg/mockito/-/81XPZlJLP_UJ.
To post to this group, send email to moc...@googlegroups.com.
To unsubscribe from this group, send email to mockito+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mockito?hl=en.

Reply all
Reply to author
Forward
0 new messages