Drawing Hands by M.C. Escher (1948)

Jeff Mesnil

Archive for August 30th, 2005


Testing an Eclipse plug-in in isolation

On August 30th, 2005 in eclipse (No Comments »)

All this post just to ask a simple question: how to test an Eclipse plug-in in isolation?

I’m currently writing an Eclipse feature to manage a server through JMX. It is composed of 3 plug-ins:

As an aside, I don’t use the MBeans directly as my domain model. To have an object-oriented domain model has two advantages:

  1. the navigation between the objects is simple to use and self-described by the API
  2. I can integrate better with Eclipse since my core objects implements IAdaptable (adapters are implemented in the UI plug-in)

So I’d like to test the Core plug-in in isolation to ensure the consistency of my domain model based on the MBeans. However I don’t want to use the “real” MBeans because most of the code I want to test is destructive and will alter the state of the managed objects on the server side making it too much difficult to run tests in isolation.

My first idea was to mock the JMX plug-in so that it returns mocked MBeans that I can use to unit test the Core plugin.
It sounds quite simple but I haven’t yet find a way to make it work…

The first dirty hack that I tried was to create a JMX Mock plug-in with the same ID and API than the real JMX plug-in and use that one in the test launch configuration but Eclipse is (understandingly!) not happy about having two plug-ins with the same ID. Anyway, it is ugly because the JMX Mock plug-in wouldn’t have any relation with the real JMX plug-in but a copy-paste…

Another dirty solution would be that the JMX plug-in itself could either return the real MBeans or the mocked ones. But is is so ugly and wrong that I really don’t want to go that way…

I searched on Google and Eclipse mailing lists about ways to test Eclipse plug-ins in isolation but I didn’t found any good advices.
In fact I haven’t found information about mocked plug-in (but thousands and thousands of plug-ins generating mocks, sigh…).

All that said, I just have two simple questions:

Disclaimer: I’m relatively new at plug-ins development and I really wonder if I’m not missing something obvious for experienced plug-ins developers…)