I am trying to run my Junit test using an Ant task as shown below:
<target name="TestDaoImpl">
<mkdir dir="${junit.output.dir}"/>
<junit fork="yes" printsummary="withOutAndErr">
<jvmarg line="${conf.dir}"/>
<formatter type="xml"/>
<test name="my.package.TestKSLDaoImpl" todir="${junit.output.dir}"/>
<classpath refid="My.classpath"/>
</junit>
</target>
In my test, I use PowerMockito for these two cases:
PowerMockito.whenNew(Convert.class).withAnyArguments().thenReturn(convert);
PowerMockito.mockStatic(MyService.class);
And Mockito:
Mockito.when(convert.getXmlKsl(folder)).thenReturn(xmlStr);
Actually, when I ran my test in Eclipse, I did not get any errors. But when I run it using Ant Task, I got the following errors:
org.mockito.exceptions.misusing.MissingMethodInvocationException:
when() requires an argument which has to be 'a method call on a mock'.
For example:
when(mock.getArticles()).thenReturn(articles);
Also, this error might show up because:
1. you stub either of: final/private/equals()/hashCode() methods.
Those methods *cannot* be stubbed/verified.
2. inside when() you don't call method on mock but on some other object.
3. the parent of the mocked class is not public.
It is a limitation of the mock engine.
at org.powermock.api.mockito.PowerMockito.when(PowerMockito.java:495)
The error is here:
PowerMockito.mockStatic(MyService.class);
===> Mockito.when(MyService.getInstance(myId)).thenReturn(myService);
I use these jars:
JUnit 4
cglib-nodep-2.2.2.jar
javassist-3.18.1-GA.jar
mockito-all-1.9.5.jar
objenesis-2.1.jar
powermock-mockito-1.5.4-full.jar
Is there a conflict with Ant and PowerMockito? Why does the test work well with eclipse, but not with Ant?
source
share