Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » rcp and junit test
rcp and junit test [message #514229] Fri, 12 February 2010 22:19 Go to next message
Eclipse User
Originally posted by: nospam.somewhere.org

How can a implement a junit test for a rcp application?

My application uses eclipse/rcp and consists of several rcp plugin
projects. Some plugins are gui and others are non-gui. A single plugin
may reference other plugins.
My first step is to implement the junit in a rcp plugin project.

Now, google search found some interesting tools: tptp agr and swtbot.
Some comercial project are found, too. But my interest in costfree tools.

questions:

1. The tptp automated gui recorder sounds good, but the documentation is
very rare. The docs i found seems to be for an older version of eclipse.
I am not sure how to control this tool :-(

Any idea?

2. SWTBOT, the docs seem to be more complete but i havent used it. Do
you think it is a worthful alternative to tptp?

3. Are there other free testing tools available?

How do you implement junit tests for rcp based applications?

regards,
markus
Re: rcp and junit test [message #514276 is a reply to message #514229] Sat, 13 February 2010 12:40 Go to previous messageGo to next message
Christian is currently offline Christian
Messages: 72
Registered: July 2009
Member
Am 12.02.2010 23:19, schrieb Ceeper:
> How do you implement junit tests for rcp based applications?
>
> regards,
> markus



On question 4: My first shot for simple rcp testing was to just write a
little IApplication that runs all the tests..
and put it in a fragment of your plugin under Test so you get full
access to all classes in the plugin.


here some exmple code for runnign the tests:

import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.app.IApplication;
import org.eclipse.equinox.app.IApplicationContext;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;

import uc.crypto.BloomFilterTest;
import uc.protocol.hub.AdcHubTest;
import uc.protocol.hub.NmdcHubTest;

public class AllTests implements IApplication {

private static final Class<?>[] TEST_CASES= new Class[]
{BloomFilterTest.class,
NmdcHubTest.class,
AdcHubTest.class};

public Object start(IApplicationContext context) throws Exception {

for (Class<?> c:TEST_CASES) {
Result res = JUnitCore.runClasses(c);
if (res.wasSuccessful()) {
System.out.println("Success: "+c.getSimpleName()+" NrOfTest:
"+res.getRunCount()+" Time: "+(res.getRunTime()/1000)+"sec");
} else {
for (Failure f: res.getFailures()) {
System.out.println(f.getDescription().getDisplayName());
f.getException().printStackTrace();
break;
}
System.out.println("Failure: "+c.getSimpleName());
}
}




return Status.OK_STATUS;
}

public void stop() {

}

}

probably there is a better way... though that pretty much was simple and
did the Job for me...

Christian
Re: rcp and junit test [message #514416 is a reply to message #514229] Mon, 15 February 2010 09:27 Go to previous message
Mickael Istria is currently offline Mickael Istria
Messages: 755
Registered: July 2009
Location: Grenoble, France
Senior Member
Ceeper a écrit :
> 2. SWTBOT, the docs seem to be more complete but i havent used it. Do
> you think it is a worthful alternative to tptp?

I am a big fan of SWTBot, and I think it is worth trying. It makes writing user-level tests very easy. Moreover, it can be integrated in headless unit tests suite as easily as simple JUnit tests.


> How do you implement junit tests for rcp based applications?

Simply write some JUnit plugins tests (ie JUnit tests that have access to Eclipse runtime, UI and workbench classess). When writing them you can launch them from Eclipse as you would run simple JUnit tests.
If you want to test them in your built RCP application, you'll have to:
* Provide test, and dependency and Eclipse test framework in your application (for example as an additional feature).
* Run your test headless from inside of your application using the org.eclipse.test.uitestapplication (see http://www.eclipse.org/articles/Article-PDE-Automation/autom ation.html)
The difficulty here is to provide right dependencies so that your test will start.

--
Mickael Istria - BonitaSoft S.A.
http://www.bonitasoft.com/products/downloads.php
Previous Topic:small exclamation icon on build.properties
Next Topic:Problem while exporting RCP
Goto Forum:
  


Current Time: Tue Sep 23 04:20:33 GMT 2014

Powered by FUDForum. Page generated in 0.02268 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software