Search code examples
eclipsetestingjunitrcp

JUnit Testing for Eclipse RCP. How to do it?


I would like to write JUnit test for my Eclipse RCP while I continue developing the code. When starting the application the different plugins initialize variables of various plugins/classes (mostly within their start methods) which are needed for the correct functionality. If this initialization doesn't happen, it is impossible to test code because it depends on those values.

How do I solve this issue without creating a lot of dummy values? What is the general approach to testing Eclipse RCPs?


Solution

  • You're facing a common problem: Too many dependencies. You need to cut them.

    With Eclipse 3, this is going to be somewhat hard. Try to split the code into things that depend on the Eclipse platform running and everything else. Eclipse often uses interfaces, so you can test many things using mocks.

    With e4, things got more simple since many services will be injected, making mocking and testing even easier.

    But the goal must always be to have as much code as possible that doesn't depend on SWT or the platform. Create your own interfaces if you have to. The runtime imlementations just wrap Eclipse code. For tests, you can use mocks to simulate the Eclipse runtime.