我可以使用Java FEST阻止使用System.exit进行应用程序测试吗?

时间:2013-10-09 15:41:52

标签: java swing testing fest

我尝试用FEST测试我的应用程序。和大多数其他应用程序一样,我在那里有一个System.exit()命令。当我什么都不做并运行所有测试时,第一次调用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

1 个答案:

答案 0 :(得分:2)

是的,NoExitSecurityManager可用于防止测试被中断,因为测试中的应用程序调用{​​{1}}。

在这种情况下抛出System.exit并将其堆栈跟踪写入控制台,但除非您捕获异常,否则它不会阻止测试继续并成功,因为它在不同的线程上运行。

catch可能位于未捕获的异常处理程序中。如果您的代码中有ExitException之类的内容,您将获得无限循环。在测试期间需要禁用此类异常处理程序。