我是否可以阻止使用Java FEST进行应用程序测试以执行System.exit?
我尝试用FEST测试我的应用程序。与大多数其他应用程序一样,我在其中有一个我是否可以阻止使用Java FEST进行应用程序测试以执行System.exit?,java,swing,testing,fest,Java,Swing,Testing,Fest,我尝试用FEST测试我的应用程序。与大多数其他应用程序一样,我在其中有一个System.exit()命令。当我什么都不做并运行所有测试时,当第一次调用System.exit()方法时,测试运行将中止 我搜索了一下,发现了一些东西。这似乎是我一直在寻找的,但它导致了一个意想不到的行为。当我调用System.exit()时,我在System.exit()中得到一个无限循环,它每次抛出org.fest.swing.security.ExitException。如果捕获到异常,则应用程序不会关闭,测试也
System.exit()
命令。当我什么都不做并运行所有测试时,当第一次调用System.exit()
方法时,测试运行将中止
我搜索了一下,发现了一些东西。这似乎是我一直在寻找的,但它导致了一个意想不到的行为。当我调用System.exit()
时,我在System.exit()
中得到一个无限循环,它每次抛出org.fest.swing.security.ExitException
。如果捕获到异常,则应用程序不会关闭,测试也不会结束
有人用过这样的节日吗
有关更多信息,请参阅完整的stacktrace:
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是的,
NoExitSecurityManager
可用于防止测试中断,因为被测应用程序调用了System.exit
在这种情况下会抛出ExitException
,并将其堆栈跟踪写入控制台,但除非捕获异常,否则它不会阻止测试继续和成功,因为它在不同的线程上运行
捕获可能位于未捕获的异常处理程序中。如果您的代码中有类似于
Thread.setDefaultUncaughtExceptionHandler(…)
的内容,您将得到无限循环。测试期间需要禁用此类异常处理程序。是否应标记编码的UI?我没有使用过线程。setDefaultUncaughtExceptionHandler(…)我甚至不知道存在类似的情况。还有其他可能的原因吗?请用代码片段增强您的问题-NoExistSecurityManager的初始化、导致问题的测试代码等。