How to create Unit Test for RCP applications

This page is dedicated to Eclipse developpers that need to create Unit Test for RCP applications such as TOS. For SWTBot tests, see SwtBot tests.

The best way to create JUnit test for an Eclipse plugin is to start from a Plugin Fragment, that will allow to access to classes that may not be exported by the plugin itself as fragments have the same right as the plugin itself.
Fragment is also usefull because is may not be included in the plugin delivered to the users.

For talend products unit test we will be using JUnit 4.

1) So first create a new '''Fragment project'''.

I would suggest the name of the project be the name of the plug-in (as we usually do). This name should be the name of the plug-in to be tested suffixed with .test.

Example to test the plugin named:           org.talend.core 
create a fragment of this plugin named:     org.talend.core.test

The Host plug-in ID is the ID of the plugin to be tested.

2) Edit fragment dependencies.

Edit the fragment dependencies by opening the file 'META-INF\MANIFEST.MF' and choosing the 'Dependencies' tab. Add the org.junit4 plugin

3) Create the Test case.

Create the test case, using 'file → new → Other → Junit Test Case'

Select JUnit 4 test.
Select the class to Test.
Specify the package of the test class, should be the same as the class to test so that the test case may access package private classes and methods.
Specify the name of the test class, should be the same than the class to test + Test in the end.

Example : the tested class is        org.talend.core.model.process.BlockCode
the test class should be named       org.talend.core.model.process.BlockCodeTest

Write your test case

4) run the test case.

To run the newly created tests, create a new 'JUnit Plugin Test' configuration in the Run Dialog

Test Tab : Select JUnit 4 test runner
Test Tab : choose the project where the tests are located.
Test Tab : you may alternatively run all the unit test available by selecting Run a single test (the name is misleading :) and choosing the project test.all.test.suite and the class org.talend.test.AllTestsForJUnit4Suite. This project may be found in the svn repository named commons/development.

Main Tab : Clear the location in Workspace Data
Main Tab : choose the product in the Run a Product.

Arguments Tab : You can specify the project root as argument after a '-data' param

Plug-ins Tab : Setup the plugins to included in the launch according to the product you want to launch

then run it as any executable configuration in eclipse and pray all your tests pass ;)

More information in Testing training presentation.


The data used for Unit Tests are located on ##### You should copy them all localy and change the '-data <root_path>' accordingly in the 'argument tab'

 
dev/rcp_unit_test.txt · Last modified: 2011/12/17 12:52 (external edit)
 
 
Recent changes RSS feed Driven by DokuWiki