JUnit Eclipse VS Ant

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?

+4
source share
1 answer

Why tests can pass in Eclipse, but crash when starting at the command prompt:

, , IDE, , , . IDE -. , IDE JUnit, , .

, , , Ant IDE. , , , , .

"" , , , , . , Mockito-All 1.9.5, Hamcrest 1.1, Hamcrest 1.3, . , , , . .

JUnit 4, Mockito-all 1.9.5 Hamcrest. : JUnit 4.11, Mockito-core 1.9.5 Hamcrest 1.3. , Eclipse .

Ant PowerMockito:

Ant - PowerMock. , . Maven Gradle .

+2

Source: https://habr.com/ru/post/1541609/


All Articles