【问题标题】:Can I prevent application test with Java FEST from doing System.exit?我可以阻止使用 Java FEST 执行 System.exit 的应用程序测试吗?
【发布时间】:2013-10-09 15:41:52
【问题描述】:

我尝试使用 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)

问候,世界树

【问题讨论】:

  • 应该标记编码的 UI 吗?

标签: java swing testing fest


【解决方案1】:

是的,NoExitSecurityManager 可用于防止测试因被测应用程序调用System.exit 而被中断。

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

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

【讨论】:

  • 我没用过 Thread.setDefaultUncaughtExceptionHandler(...) 我什至不知道有这样的东西存在。还有其他可能的原因吗?
  • 请使用代码 sn-ps 增强您的问题 - NoExistSecurityManager 的初始化、导致问题的测试代码等。
猜你喜欢
  • 2019-04-26
  • 1970-01-01
  • 2015-03-08
  • 2014-05-03
  • 1970-01-01
  • 2015-03-28
  • 1970-01-01
  • 1970-01-01
  • 2020-08-21
相关资源
最近更新 更多