Great, thanks for the reply.

Please find the bug/patch at
https://bugs.eclipse.org/bugs/show_bug.cgi?id=259787

All the best,
Toby



> Message: 4
> Date: Tue, 30 Dec 2008 05:56:21 +0530
> From: Ketan Padegaonkar <ketanpadegaon...@gmail.com>
> Subject: Re: [SWTBot-users] JUnit 4 test runner
> To: swtbot-users@lists.sourceforge.net
> Message-ID: <49596aad.2090...@gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Nice :)
>
> Could you file the patch at bugs.eclipse.org, and I could look at it.
>
> One of the reasons for not having junit 4 support is that junit4 support
> is lacking in the eclipse testing framework
> (https://bugs.eclipse.org/bugs/show_bug.cgi?id=153429)
>
> Please add a comment to the above bug to let the folks know that you
> need it as well.
>
> -- Ketan
>
> On 30/12/08 18:07, Toby wrote:
> > Hello,
> >
> > Just started looking at SWTBot which looks great. I wondered though why
> > there didn't seem to be JUnit 4 test runner support? I couldn't see
> > anything in the source so I created a runner (see patch below) which
> > means you can start a test like below.
> >
> >
> > @RunWith(SWTBotRunner.class)
> > public class FooTest {
> >
> > private final SWTBot bot = new SWTBot();
> >
> > @BeforeClass
> > public static void startTheApplication() throws TimeoutException,
> > InterruptedException {
> > new Thread(new Runnable() {
> > public void run() {
> > Main.main();
> > }
> > }).start();
> > waitForDisplay(5, SECONDS);
> > }
> >
> > @Test
> > public void rightClickStartsConfiguration() throws Exception {
> > bot.button("click me").click();
> > bot.button("you just clicked me!").click();
> > }
> >
> > private static void waitForDisplay(long timeout, TimeUnit unit) throws
> > TimeoutException, InterruptedException {
> > long endTime = System.currentTimeMillis() + unit.toMillis(timeout);
> > while (System.currentTimeMillis() < endTime) {
> > try {
> > Display display = SWTUtils.display();
> > if (display != null)
> > return;
> > } catch (Exception e) {
> > }
> > Thread.sleep(100);
> > }
> > throw new TimeoutException("timed out");
> > }
> >
> > }
> >
> > Seems to work for me, does it look about right to you guys?
> >
> > Cheers,
> > Toby
> >
> >
> > ### Eclipse Workspace Patch 1.0
> > #P net.sf.swtbot.finder
> > Index: .classpath
> > ===================================================================
> > --- .classpath (revision 1233)
> > +++ .classpath (working copy)
> > @@ -1,11 +1,12 @@
> > -<?xml version="1.0" encoding="UTF-8"?>
> > -<classpath>
> > - <classpathentry kind="con"
> >
> path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
> > - <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
> > - <accessrules>
> > - <accessrule kind="accessible" pattern="**"/>
> > - </accessrules>
> > - </classpathentry>
> > - <classpathentry kind="src" path="src"/>
> > - <classpathentry kind="output" path="bin"/>
> > -</classpath>
> > +<?xml version="1.0" encoding="UTF-8"?>
> > +<classpath>
> > + <classpathentry kind="con"
> >
> path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
> > + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
> > + <accessrules>
> > + <accessrule kind="accessible" pattern="**"/>
> > + </accessrules>
> > + </classpathentry>
> > + <classpathentry kind="src" path="src"/>
> > + <classpathentry kind="lib"
> > path="/net.sf.swtbot.build/libs/junit-4.4.jar"/>
> > + <classpathentry kind="output" path="bin"/>
> > +</classpath>
> > Index: src/net/sf/swtbot/SWTBotRunner.java
> > ===================================================================
> > --- src/net/sf/swtbot/SWTBotRunner.java (revision 0)
> > +++ src/net/sf/swtbot/SWTBotRunner.java (revision 0)
> > @@ -0,0 +1,41 @@
> > +package net.sf.swtbot;
> > +
> > +import java.io.File;
> > +import java.lang.reflect.InvocationTargetException;
> > +import java.lang.reflect.Method;
> > +
> > +import net.sf.swtbot.utils.ClassUtils;
> > +
> > +import org.junit.internal.runners.InitializationError;
> > +import org.junit.internal.runners.JUnit4ClassRunner;
> > +import org.junit.internal.runners.TestMethod;
> > +
> > +public class SWTBotRunner extends JUnit4ClassRunner {
> > +
> > + public SWTBotRunner(Class<?> klass) throws InitializationError {
> > + super(klass);
> > + }
> > +
> > + @Override
> > + protected TestMethod wrapMethod(final Method method) {
> > + return new TestMethod(method, getTestClass()) {
> > + @Override
> > + public void invoke(Object test) throws IllegalArgumentException,
> > IllegalAccessException, InvocationTargetException {
> > + try {
> > + method.invoke(test);
> > + } catch (Throwable e) {
> > + captureScreenshot();
> > + throw new InvocationTargetException(e);
> > + }
> > + }
> > + };
> > + }
> > +
> > + private void captureScreenshot() {
> > + String fileName = "screenshots/screenshot-" +
> > ClassUtils.simpleClassName(getClass()) + "." + getName() + ".png";
> > + new File("screenshots").mkdirs();
> > + SWTBotTestCase.captureScreenshot(fileName);
> > + }
> > +
> > +}
> > +
> >
> >
> > --
> > Toby
> >
> >
> > ------------------------------------------------------------------------
> >
> >
> ------------------------------------------------------------------------------
> >
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > SWTBot-users mailing list
> > SWTBot-users@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/swtbot-users
> > http://swtbot.org/ - a functional testing tool for SWT/Eclipse
> >
>
>
>
> ------------------------------
>
>
> ------------------------------------------------------------------------------
>
>
> ------------------------------
>
> _______________________________________________
> SWTBot-users mailing list
> SWTBot-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/swtbot-users
>
>
> End of SWTBot-users Digest, Vol 10, Issue 3
> *******************************************
>



-- 
Toby
------------------------------------------------------------------------------
_______________________________________________
SWTBot-users mailing list
SWTBot-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swtbot-users
http://swtbot.org/ - a functional testing tool for SWT/Eclipse

Reply via email to