I have followed the instructions here (
http://stuffthathappens.com/blog/2007/09/14/junit-3x-and-the-event-dispatch-thread/)
to write a JUnit4 test runner that makes sure that tests are run on the
event dispatch thread. Sure enough, if I assertTrue(
java.awt.EventQueue.isDispatchThread()) inside a test that is properly
annotated with @RunWith(EDTRunner.class), it passes. Cool; I can now run my
Swing-centric tests with surefire/mvn.
But, now, no matter what I do inside one of these Swing tests or in the
EDTRunner I cannot get any frame that it creates to stay up. Any visual
artifacts, properly created on the EDT and carefully guarded with
assertTrue(EventQueue.isDispatchThread()), flicker up for a trillionth of a
second, if I'm lucky, and then immediately disappear.
This seems to be somehow related to the fact that the tests I run are under
surefire/mvn. Is there some way to tell surefire to...well, I'm not even
sure what I'm asking.
What I want is in a test where I do:
final JFrame frame = new JFrame("someTitle");
frame.setContentPane(someContentPane);
frame.pack();
frame.setVisible(true);
...and where I run this test via this construct in my EDTRunner:
EventQueue.invokeAndWait(/* a runnable to cause EDTRunner.super.run() to
fire */);
...I want the frame to "stick around", and not immediately vanish. In a
normal standalone situation, the above construct would suffice.
What is surefire doing that prevents this frame from sticking around?
Thanks,
Laird