我正在使用Junit 4.x來測試方法。JUnit - 不等待測試方法完成
測試下的方法預計會拋出IllegalArgumentException。該方法是一種阻塞方法(同步),它在內部使遠程ssh連接執行腳本並捕獲結果,或拋出異常。
爲了測試這個,我寫了下面的JUnit測試代碼。
@Test (timeout=3000, expected=IllegalArgumentException.class)
public final void testReadFolderWithInvalidFolder() {
final String folder = "/home/rv_nath/xxxyyyZzz";
rfc.readFolder(folder);
}
上述testReadFolder()方法被認爲檢查預期的異常是否被拋出或不)之前等待高達3秒(becoz超時= 3000)。但是它立即返回,報告測試用例失敗。
任何人都可以幫我弄清楚上面出了什麼問題。如果需要更多細節,請告訴我。
這裏是Junit的故障跟蹤...
java.lang.AssertionError: Should have thrown IllegalArgumentException. at org.junit.Assert.fail(Assert.java:91) at com.comviva.remotefilebrowser.server.RemoteFileCaseTest.testReadFolderWithInvalidFolder(RemoteFileCaseTest.java:94) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:616) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.internal.runners.statements.FailOnTimeout$1.run(FailOnTimeout.java:28)
是否有Junit4超時實現中的錯誤,還是我失去了一些東西?因爲,如果我在調試模式下運行測試用例(並通過它進行跟蹤,那麼完成遠程執行需要一定的時間,但它確實可行並且測試用例通過)。如果我選擇運行這個測試用例,而不是調試那麼只會出現這個問題。
感謝和問候, RV