Problem with Testlistener in headless Mode [message #512898] |
Mon, 08 February 2010 10:23 |
speedprincess Messages: 5 Registered: February 2010 |
Junior Member |
|
|
Hello,
First I like SWTBot, because it has a great api for do gui tests for rcp applications.
Now to my problem. During the test runs I want to collect the testresults to create a testprotocoll in a special style. I use eclipse 3.4.2 and junit 4.3.1
Therefor I have create a class Junit4TestListener, which extends RunListener. In this class I override all Methodes, currentla with simple system.out messages. Because I want to know, when the will be call.
In addition I have a Testrunner which extends the SWTBotApplicationLauncherClassRunner. In this class I register my listener.
In my testclass I add the line @RunWith(MyJunitTestRunner.class).
When I now run my tests in the eclipse IDE. The methode testRunStarted(), which should be called at the beginning of the test, will not be called. But that is ok. I can use the constructor instaed of this methode.
The problem ist when I run this test headless with ant. Because headless, the methode testRunFinished(), which should be called at the end of my tests, will not be called. So I can not finish my testprotocoll.
I add the code of my testclass, the listener and the runner.
Please can anybody try this in a plug-in and say whats the mistake. Or why the methode testRunFinished at the end of the test will not be invoked by a headless test.
Code Testlistener
import org.junit.runner.Description;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunListener;
public class Junit4TestListener extends RunListener {
@Override
public void testFailure(Failure failure) throws Exception {
System.out.println("testFailure");
super.testFailure(failure);
}
@Override
public void testFinished(Description description) throws Exception {
System.out.println("testFinished");
super.testFinished(description);
}
@Override
public void testRunFinished(Result result) throws Exception {
System.out.println("testRunFinished");
super.testRunFinished(result);
}
@Override
public void testRunStarted(Description description) throws Exception {
System.out.println("testRunStarted");
super.testRunStarted(description);
}
@Override
public void testStarted(Description description) throws Exception {
System.out.println("testStarted");
super.testStarted(description);
}
}
Code TestRunner
import org.eclipse.swtbot.swt.finder.junit.SWTBotApplicationLauncherClassRunner;
import org.junit.runner.notification.RunListener;
import org.junit.runner.notification.RunNotifier;
public class MyJunitTestRunner extends SWTBotApplicationLauncherClassRunner {
private static RunListener testListener = new Junit4TestListener();
public MyJunitTestRunner(Class<?> klass) throws Exception {
super(klass);
}
@Override
public void startApplication() {
}
public void run(RunNotifier notifier) {
notifier.removeListener(testListener);
notifier.addListener(testListener);
super.run(notifier);
}
}
Code for the testclass
import static org.junit.Assert.assertNotNull;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import de.xcom.swtbot.headless.junit.MyJunitTestRunner;
@RunWith(MyJunitTestRunner.class)
public class BaseTest {
static SWTWorkbenchBot bot = new SWTWorkbenchBot();
@BeforeClass
public static void setUp()
{
bot = new SWTWorkbenchBot();
try{
bot.viewByTitle("Welcome").close();
} catch (WidgetNotFoundException e) {
}
}
@Test
public void openView() throws Exception
{
bot.viewByTitle("Outline").close();
bot.menu("Window").menu("Show View").menu("Outline").click();
assertNotNull(bot.viewByTitle("Outline"));
}
|
|
|
Re: Problem with Testlistener in headless Mode [message #513026 is a reply to message #512898] |
Mon, 08 February 2010 15:38 |
Ketan Padegaonkar Messages: 873 Registered: July 2009 |
Senior Member |
|
|
Hi,
You should be extending from SWTBotJunit4ClassRunner and not
SWTBotApplicationLauncherClassRunner.
SWTBotApplicationLauncherClassRunner is (mostly) for plain swt
applications that need to be launched in another application.
-- Ketan
On 2/8/10 2:23 AM, speedprincess wrote:
> Hello,
>
> First I like SWTBot, because it has a great api for do gui tests for rcp
> applications.
>
> Now to my problem. During the test runs I want to collect the
> testresults to create a testprotocoll in a special style. I use eclipse
> 3.4.2 and junit 4.3.1
>
> Therefor I have create a class Junit4TestListener, which extends
> RunListener. In this class I override all Methodes, currentla with
> simple system.out messages. Because I want to know, when the will be call.
>
> In addition I have a Testrunner which extends the
> SWTBotApplicationLauncherClassRunner. In this class I register my listener.
>
> In my testclass I add the line @RunWith(MyJunitTestRunner.class).
> When I now run my tests in the eclipse IDE. The methode
> testRunStarted(), which should be called at the beginning of the test,
> will not be called. But that is ok. I can use the constructor instaed of
> this methode.
>
> The problem ist when I run this test headless with ant. Because
> headless, the methode testRunFinished(), which should be called at the
> end of my tests, will not be called. So I can not finish my testprotocoll.
> I add the code of my testclass, the listener and the runner.
> Please can anybody try this in a plug-in and say whats the mistake. Or
> why the methode testRunFinished at the end of the test will not be
> invoked by a headless test.
>
> Code Testlistener
> import org.junit.runner.Description;
> import org.junit.runner.Result;
> import org.junit.runner.notification.Failure;
> import org.junit.runner.notification.RunListener;
>
> public class Junit4TestListener extends RunListener {
>
> @Override
> public void testFailure(Failure failure) throws Exception {
> System.out.println("testFailure");
> super.testFailure(failure);
> }
>
> @Override
> public void testFinished(Description description) throws Exception {
> System.out.println("testFinished");
> super.testFinished(description);
> }
>
> @Override
> public void testRunFinished(Result result) throws Exception {
> System.out.println("testRunFinished");
> super.testRunFinished(result);
> }
>
> @Override
> public void testRunStarted(Description description) throws Exception {
> System.out.println("testRunStarted");
> super.testRunStarted(description);
> }
>
> @Override
> public void testStarted(Description description) throws Exception {
> System.out.println("testStarted");
> super.testStarted(description);
> }
> }
>
>
> Code TestRunner
> import
> org.eclipse.swtbot.swt.finder.junit.SWTBotApplicationLaunche rClassRunner;
> import org.junit.runner.notification.RunListener;
> import org.junit.runner.notification.RunNotifier;
>
> public class MyJunitTestRunner extends
> SWTBotApplicationLauncherClassRunner {
>
> private static RunListener testListener = new Junit4TestListener();
>
> public MyJunitTestRunner(Class<?> klass) throws Exception {
> super(klass);
> }
>
> @Override
> public void startApplication() {
> }
>
> public void run(RunNotifier notifier) {
> notifier.removeListener(testListener); notifier.addListener(testListener);
> super.run(notifier);
> }
>
> }
>
>
> Code for the testclass
> import static org.junit.Assert.assertNotNull;
> import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
> import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundExcep tion;
> import org.junit.BeforeClass;
> import org.junit.Test;
> import org.junit.runner.RunWith;
> import de.xcom.swtbot.headless.junit.MyJunitTestRunner;
>
>
> @RunWith(MyJunitTestRunner.class)
> public class BaseTest {
>
> static SWTWorkbenchBot bot = new SWTWorkbenchBot();
> @BeforeClass
> public static void setUp()
> {
> bot = new SWTWorkbenchBot();
> try{
> bot.viewByTitle("Welcome").close(); } catch (WidgetNotFoundException e) {
> }
> }
> @Test
> public void openView() throws Exception
> {
> bot.viewByTitle("Outline").close();
> bot.menu("Window").menu("Show View").menu("Outline").click();
> assertNotNull(bot.viewByTitle("Outline"));
> }
>
>
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03334 seconds