Test Driving Eclipse Plugins

This week I started writing a few automated test cases for the jbehave eclipse plugin. I used Beck’s and Gamma’s “Contributing to Eclipse” as a starting point. They provide a simple test fixture that allows you to create java projects, packages and classes. I created a simple project with a trivial class and an even more trivial jbehave test case and launched the test case using the jbehave plugin. Then I wanted to verify the output that is been written to the console and my synchronsation problems started.

So I came up with two issues:

  1. Some things like the autobuild run in background jobs, so that you have got to wait for those jobs to finish before verifying. For the autobuild there is a simple solution:

    Platform.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD, null);

  2. The second issue was around the update of the console, which happens in the UI thread. Unfortunatly the testcase runs in the UI thread as well, so a Thread.sleep() won’t help. The key is calling Display’s readAndDispatch() and sleep() methods to get the event queue processed while waiting. It’s still a bit awkward to work with delays, but I couldn’t come up with a better way.

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.