我想通過一個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意味着「小鼻涕」。就這樣 –