For those of you spend your days working in Eclipse and trying to build rich client applications (RCP) the following piece of arcana will be useful. As your developing RCP applications you will undoubtedly need to test classes that require the Display, access to Graphics or other classes that require a running Application. When I first encountered this problem I thought that I was boxed in by Eclipse – but thanks for the work of David Saff you can. The secret sauce: JUnit Plugin tests.
- To run the tests choose ‘Run…’ either via the context menu in the package explorer or via the Run menu item.
- Choose JUnit Plug-in test (not plain old Junit) This provides the tests with access to their plug-in’s plugin class – very important if you want to access the filesystem or other resources under eclipse’s control (Display, …)
- Use the new button either top left of the dialog or via the context menu. A new test will be created that should have the plugin/package/testcase that you selected as its target.
- Switch to the main tab and under ‘Program to run’ switch from org.eclipse.ui.workbench to [No Application] – Headless. This avoids have an IDE popup and disappear at the start of your tests. On my machine this shaves 3-4 seconds from the test startup time.
- Switch to the plug-ins tab and the ‘Choose plug-ins and fragments’ radio button
- Click ‘Deselect All’ the existing plugins.
- Select your test Plugin.
- Click ‘Add Required’. In theory this shouldn’t make any difference in startup times since Eclipse shouldn’t be loading these extra plug-ins. In reality I can spot a one to two second difference
I strongly recommend creating one configuration for the each test plugin so that you can run all the tests for that plugin to see if changes you’ve made break any tests.
One last thought: Test plugins should be created as plug-in fragments to gain the benefit of being able to the benefit of package level access to the classes they’re testing.
BTW if you’re getting tired of the Eclipse related stuff don’t worry this will be the last for a while.
» Next Carnival of Agilists for June 22/07 – In Progress
See all blog posts