For example, it would be really nice if I could specify a
java.util.concurrent.Executor to run the test method on in the test
annotation. For example:
@Test(executor=SwingExecutor.class)
public void testMyComponentOnTheEDT() throws Exception {
// this test code is executed on the EDT
}
The test runner could submit a FutureTask that runs the test method to
the Executor specified in the annotation. The test runner would wait
for the test method to finish running to see if it throws an
exception. If it throws an exception, it would be re-thrown back to
the original test runner thread. You could have different Executor
implementations that run tasks on the Swing EDT, the SWT EDT, a thread
pool, or any implementation of java.util.concurrent.Executor.
--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
I've been using a utility class similar to FEST's GuiActionRunner:
@Test
public void testMyComponent() throws Exception {
EDTUtils.submitLater(this, "doTestMyComponent");
}
public void doTestMyComponent() throws WhateverException {
// This code runs in the EDT
}
Internally, the submitLater method creates a FutureTask that uses
reflection to run the specified method. The FutureTask is submitted
to an Executor that uses SwingUtilities#submitLater to run the
FutureTask on the EDT. It then calls FutureTask#get to wait for the
task to complete, and either retrieve the optional return value or
rethrow the WhateverException back onto the test runner thread. The
doTestMyComponent method could optionally return a value which would
be returned by submitLater. The submitLater method can also take an
optional var-args array of parameters to pass into
doTestMyComponent.
If I could somehow configure the test runner as I originally
suggested, I think it would be cleaner. I would not have to write two
separate methods, not have to use reflection or inner classes to
invoke doTestMyComponent, and be a bit more self-documenting because I
could specify the WhateverException in the annotated test method
rather than an arbitrary Exception.
Thanks for the quick replies,
Bruce
On Jan 15, 2:31 pm, Alex Ruiz <alex.ruiz...@gmail.com> wrote:
> Hi Cedric,
>
> with invokeLater the test thread will never know about exceptions thrown in
> the EDT.
>
> Bruce, you can do the same with FEST's GuiActionRunner (please seehttp://alexruiz.developerblogs.com/?p=160) After replying to your comment
> on my blog, I realized that a SwingExecutor would not be necessary if you
> use GuiActionRunner
>
> Cheers,
> -Alex
>
> 2010/1/15 Cédric Beust ♔ <cbe...@google.com>
>
> > Hi Bruce,
>
> > Why not simply call SwingUtilities#invokeLater in your test method?
>
> > --
> > Cedric
>
> > On Fri, Jan 15, 2010 at 11:00 AM, Bruce Alspaugh <alspau...@gmail.com>wrote:
>
> >> Does TestNG provide a way to tell the test runner that you would like
> >> to run a test method on a particular thread? This becomes important
> >> when testing AWT, Swing, and SWT code because the components must be
> >> created and accessed on the Event Dispatch Thread.
>
> >> For example, it would be really nice if I could specify a
> >> java.util.concurrent.Executor to run the test method on in the test
> >> annotation. For example:
>
> >> @Test(executor=SwingExecutor.class)
> >> public void testMyComponentOnTheEDT() throws Exception {
> >> // this test code is executed on the EDT
> >> }
>
> >> The test runner could submit a FutureTask that runs the test method to
> >> the Executor specified in the annotation. The test runner would wait
> >> for the test method to finish running to see if it throws an
> >> exception. If it throws an exception, it would be re-thrown back to
> >> the original test runner thread. You could have different Executor
> >> implementations that run tasks on the Swing EDT, the SWT EDT, a thread
> >> pool, or any implementation of java.util.concurrent.Executor.
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "testng-users" group.
> >> To post to this group, send email to testng...@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> testng-users...@googlegroups.com<testng-users%2Bunsu...@googlegroups.com>
> >> .
> >> For more options, visit this group at
> >>http://groups.google.com/group/testng-users?hl=en.
>
> > --
> > ***Cédric
> > *
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "testng-users" group.
> > To post to this group, send email to testng...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > testng-users...@googlegroups.com<testng-users%2Bunsu...@googlegroups.com>