java JUnit Eclipse VS Ant
我正试图通过Ant任务启动Junit测试,如下所示:
<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.when(convert.getXmlKsl(folder)).thenReturn(xmlStr);
实际上,当我在Eclipse中运行测试时,我没有得到任何错误。 但当我通过Ant Task启动它时,我发现了以下错误:
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
与ant和PowerMockito有冲突吗? 为什么eclipse可以很好地运行测试,而Ant却不能
共 (0) 个答案