UnfinishedVerificationException at Mockito.mock(Object.class);

8,099 views
Skip to first unread message

ka...@quipsy.de

unread,
May 2, 2014, 8:36:01 AM5/2/14
to moc...@googlegroups.com
I'm using Mockito 1.9.5 (JUnit 4.11) on JRE 8 to mock Object.class (or any other class or interface):

package de.quipsy.inspections.roster.ui;
import org.junit.Test;
import org.mockito.Mockito;

public class XXInspectionRosterUITest {
    @Test public void myTest() {
        Mockito.mock(Object.class);
    }
}


This test is running well!

Now I simply strip "XX" from the the class name, and then the fest fails with the following error (in both, Eclipse Kepler and using Maven from CLI):

org.mockito.exceptions.misusing.UnfinishedVerificationException
Missing method call for verify(mock) here:
-> at de.quipsy.inspections.roster.ui.cli.InspectionRosterCLITest.shouldStartInspectionJobs(InspectionRosterCLITest.java:76)

Example of correct verification:
    verify(mock).doSomething()

Also, this error might show up because you verify either of: final/private/equals()/hashCode() methods.
Those methods *cannot* be stubbed/verified.

at de.quipsy.inspections.roster.ui.InspectionRosterUITest.myTest(InspectionRosterUITest.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

This is totally weird, as I do not use verify() anywhere in that class as you can see!

Now it gets even more weird. I have another test in a different package of which the test class name begins similar to the above class. If I append the two XX to THAT ONE instead of THIS ONE, the problems also GONE -- but only using Eclipse's JUnit runner; Maven from CLI still fails. Weird and really scary!

To sum up, it looks like there is a severe mixup of test class names in Mockito 1.9.5 and it would be really great if one of the mockito contributors could work with me to get this really scary bug identified ASAP! :-)

Regards
-Markus

Eric Lefevre-Ardant

unread,
May 5, 2014, 4:10:40 AM5/5/14
to moc...@googlegroups.com
Hi Markus,

It seems very unlikely that Mockito would mixup class names.

I notice something very strange in the trace you provide:

at de.quipsy.inspections.roster.ui.cli.InspectionRosterCLITest.shouldStartInspectionJobs(InspectionRosterCLITest.java:76)
<snip>
at de.quipsy.inspections.roster.ui.InspectionRosterUITest.myTest(InspectionRosterUITest.java:18)

So, the error seems to be in InspectionRosterCLITest, not in InspectionRosterUITest. As for InspectionRosterUITest appearing in the traces, I'm not sure, but maybe investigating will lead to more insight?


--
You received this message because you are subscribed to the Google Groups "mockito" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito+u...@googlegroups.com.
To post to this group, send email to moc...@googlegroups.com.
Visit this group at http://groups.google.com/group/mockito.
For more options, visit https://groups.google.com/d/optout.

Graham Allan

unread,
May 5, 2014, 10:15:18 AM5/5/14
to moc...@googlegroups.com
Hey Markus,

I recently found a similar problem, which led me to this StackOverflow answer:


My guess is that InspectionRosterCLITest does not correctly use Mockito.verify() and it's reported when InspectionRosterUITest runs, as that's just the way Mockito checks that a verification is complete. As mentioned in the SO answer, failure to verify in test N will be reported as an error while executing test N+1. 

As for removing 'XX', and the difference between Maven and Eclipse, I would not be surprised if they run tests in completely different orders. I don't recall any guarantees about the order in which test classes run from either runner: it could be alphabetical, it could be the order they appear in the classpath, etc.

HTH,
Graham
Reply all
Reply to author
Forward
0 new messages