我想通过一个Ant任务来启动我的JUnit测试,如下图所示:的JUnit的Eclipse VS蚂蚁
<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>
在我的测试我使用PowerMockito,这两种情况:
PowerMockito.whenNew(Convert.class).withAnyArguments().thenReturn(convert);
PowerMockito.mockStatic(MyService.class);
和Mockito:
Mockito.when(convert.getXmlKsl(folder)).thenReturn(xmlStr);
其实当我在Eclipse中运行我的测试时,我没有得到任何错误。 但是当我通过Ant任务启动它,我得到这个错误:
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)
的错误是在这里:
PowerMockito.mockStatic(MyService.class);
===> Mockito.when(MyService.getInstance(myId)).thenReturn(myService);
我用这瓶:
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
是否有任何与蚂蚁和PowerMockito冲突? 为什么测试通过eclipse运行良好,但不通过Ant?
这些类型的问题(构建在命令行或IDE上工作,但不在其他类型中)的典型原因与类路径中的差异有关。通常,命令行工具和IDE将以不同方式解决依赖关系。 –
您使用的是哪种版本的JUnit? –
只是一个旁注:在西班牙语mockito意味着“小鼻涕”。就这样 –