My favorites | Sign in
Project Home Downloads Issues Source
New issue   Search
  Advanced search   Search tips   Subscriptions
Issue 174: Add support for interrupting/killing tests - Patch from Simeon Fitch
1 person starred this issue and may be notified of changes. Back to list
Status:  Fixed
Closed:  Jul 2008

Sign in to add a comment
Project Member Reported by, Jul 14, 2008
From Simeon:

So, let's say you're running a pretty big FEST-Swing test, one that
takes a couple minutes to run. In the middle of it, a Skype call comes
in. You need to answer the call, but you currently don't own the
mouse! Eventually, some frantic combination of Alt, Ctrl, Cmd, Tab,
Esc, F1-12, gets the window buried, and you can accept the call, but
you want something more "decisive" to kill the test run.

The class below offers one approach to addressing this problem, and
offer it to anyone who wants something similar.

Has anyone else implemented a similar feature and taken a different




import java.awt.*;
import java.awt.event.AWTEventListener;
import java.awt.event.KeyEvent;

 * This class provides an escape valve for the user to abort a running
 * test by pressing Ctrl + Shift + A. Easiest way to us is to call<br/
 * <pre>
 *     EmergencyAbortListener.register();
 * </pre>
 * from the @BeforeClass method.
 * @version $Revision: 1.1 $
 * @author <a href="">Simeon H.K.
 * @since Jun 30, 2008
public class EmergencyAbortListener implements AWTEventListener {

   public static void register() {
EmergencyAbortListener(), AWTEvent.KEY_EVENT_MASK);

    * Private ctor because we don't want to allow use outside of the
{@link #register} method.
   private EmergencyAbortListener() {

    * Inspect key events for magic abort sequence.
    * {@inheritDoc}
    * @see
   public void eventDispatched(AWTEvent event) {
       if(event.getID() == KeyEvent.KEY_PRESSED) {
           KeyEvent e = (KeyEvent) event;
           if(e.isControlDown() &&  e.isShiftDown() &&
               e.getKeyCode() == KeyEvent.VK_A &&
               e.getID() == KeyEvent.KEY_PRESSED) {

               // We do three things to signal an abort.
               // 1) sent an interrupt signal to main thread
               // 2) dispose all available frames.
               // 3) throw RuntimeException on AWT event thread

               for(Frame f : Frame.getFrames()) {

               throw new RuntimeException("User aborted test.");

    * Call {@link Thread#interrupt()} on main thread in attempt to
    * interrupt current FEST operation. Only affects thread if it is
    * in a {@link Object#wait()} or {@link Thread#sleep(long)}
   private void pokeMainThread() {
       Thread[] all = new Thread[Thread.activeCount()];
       for(Thread t : all) {
           if("main".equalsIgnoreCase(t.getName())) {

   /** Last resort exception handler for AWT event thread, to make
sure we
    * can get a backtrace dump when use aborts;
   public static class SimpleFallbackHandler {
       public void handle(Throwable ex) {

   static {
       // Make sure there's an exception handler that will dump a
stack trace on abort.

Jul 20, 2008
Project Member #1
Added class org.fest.swing.core.EmergencyAbortListener to abort running FEST-Swing
tests using a predefined key combination.
Status: Fixed
Nov 30, 2008
Project Member #2
Set the module as a label, instead of being part of the title.
Summary: Add support for interrupting/killing tests - Patch from Simeon Fitch
Labels: Module-fest-swing
Sign in to add a comment

Powered by Google Project Hosting