Je suis en train de lancer mon test Junit par une tâche Ant, comme ci-dessous:JUnit Eclipse VS Ant
<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>
Dans mon test, je me sers PowerMockito, pour ces deux cas:
PowerMockito.whenNew(Convert.class).withAnyArguments().thenReturn(convert);
PowerMockito.mockStatic(MyService.class);
Et Mockito:
Mockito.when(convert.getXmlKsl(folder)).thenReturn(xmlStr);
En fait, lorsque j'ai exécuté mon test dans Eclipse, je n'ai pas eu d'erreurs. Mais quand je lance par tâche Ant, j'ai eu cette erreur:
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)
L'erreur est ici:
PowerMockito.mockStatic(MyService.class);
===> Mockito.when(MyService.getInstance(myId)).thenReturn(myService);
J'utilise ce jarres:
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
Y at-il conflit avec fourmi et PowerMockito? Pourquoi le test fonctionne bien avec Eclipse mais pas avec Ant?
La cause type de ces types de problèmes (la construction fonctionne sur la ligne de commande ou l'EDI, mais pas sur l'autre) est liée aux différences dans le chemin de classe. En règle générale, les outils de ligne de commande et les IDE résolvent les dépendances différemment. –
Quelle version de JUnit utilisez-vous? –
Juste un sidenote: mockito en espagnol signifie "petite morve". C'est tout –