Problem with Testlistener in headless Mode [message #512898] |
Mon, 08 February 2010 05:23  |
Eclipse User |
|
|
|
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 10:38   |
Eclipse User |
|
|
|
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"));
> }
>
>
|
|
|
|
|
Re: Problem with Testlistener in headless Mode [message #516811 is a reply to message #512898] |
Thu, 25 February 2010 04:29  |
Eclipse User |
|
|
|
Hello,
Thanks for the answer, but the 2 log4j warnings are not the problem.
If I add correct this, I have always the same problem. Headless the methode runFinished wont be invoked, and so my testprotocoll cant finished.
Can anybody try this code and give my an advice, what I can do?
Or is there another chance to call a special methode at the end of the tests. Can I override some methode in the runner, to do this?
What is the difference between the swtbotRunner and the eclipse junit runner, that by running in the ide the methode will be invoke and in the headless mode not.
|
|
|
Powered by
FUDForum. Page generated in 1.27822 seconds