2013-10-09 60 views
-1

我嘗試用FEST測試我的應用程序。與其他大多數應用程序一樣,我在那裏有一個System.exit()命令。當我什麼都不做並且運行所有測試時,當第一次調用System.exit()方法時,測試運行會中止。我可以使用Java FEST阻止應用程序測試執行System.exit嗎?

我搜索了一下here。這似乎是我正在尋找的東西,但它會導致意想不到的行爲。當我打電話System.exit()我得到一個無限循環System.exit()其中每次拋出org.fest.swing.security.ExitException。如果我發現異常,應用程序沒有關閉,測試也不會結束。

有沒有人已經使用過這樣的FEST?

作進一步的信息完整的堆棧跟蹤:

Exception in thread "AWT-EventQueue-0" org.fest.swing.security.ExitException: Application tried to terminate current JVM with status 0 
at org.fest.swing.security.NoExitSecurityManager.checkExit(NoExitSecurityManager.java:84) 
at java.lang.Runtime.exit(Unknown Source) 
at java.lang.System.exit(Unknown Source) 
at org.luciferius.banking.swingUi.internal.SwingUiBuilder$1.windowClosed(SwingUiBuilder.java:81) 
at java.awt.AWTEventMulticaster.windowClosed(Unknown Source) 
at java.awt.Window.processWindowEvent(Unknown Source) 
at javax.swing.JFrame.processWindowEvent(Unknown Source) 
at java.awt.Window.processEvent(Unknown Source) 
at java.awt.Component.dispatchEventImpl(Unknown Source) 
at java.awt.Container.dispatchEventImpl(Unknown Source) 
at java.awt.Window.dispatchEventImpl(Unknown Source) 
at java.awt.Component.dispatchEvent(Unknown Source) 
at java.awt.EventQueue.dispatchEventImpl(Unknown Source) 
at java.awt.EventQueue.access$200(Unknown Source) 
at java.awt.EventQueue$3.run(Unknown Source) 
at java.awt.EventQueue$3.run(Unknown Source) 
at java.security.AccessController.doPrivileged(Native Method) 
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) 
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) 
at java.awt.EventQueue$4.run(Unknown Source) 
at java.awt.EventQueue$4.run(Unknown Source) 
at java.security.AccessController.doPrivileged(Native Method) 
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) 
at java.awt.EventQueue.dispatchEvent(Unknown Source) 
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) 
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) 
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) 
at java.awt.EventDispatchThread.pumpEvents(Unknown Source) 
at java.awt.EventDispatchThread.pumpEvents(Unknown Source) 
at java.awt.EventDispatchThread.run(Unknown Source) 

問候,Yggdrasil的

+0

應編碼的UI被標記? – w25r

回答

2

是的,NoExitSecurityManager可以用來防止因爲被測試的應用程序調用System.exit中斷測試。

在這種情況下會拋出ExitException,並將其堆棧跟蹤寫入控制檯,但除非您捕獲該異常,否則它不會阻止測試繼續併成功,因爲它在另一個線程上運行。

catch可能處於未捕獲的異常處理程序中。如果你的代碼中有類似Thread.setDefaultUncaughtExceptionHandler(...)的東西,你會得到無限循環。這些異常處理程序需要在測試期間禁用。

+0

我無處可用Thread.setDefaultUncaughtExceptionHandler(...)我甚至不知道這樣的事情存在。還有其他可能的原因嗎? – Yggdrasil

+0

請使用代碼片段增強您的問題 - NoExistSecurityManager的初始化,導致問題的測試代碼等。 – Mareen

相關問題