2013-10-09 57 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

相关问题