Creating a test environment for the Eclipse Testing Framework

Running unit tests with the Eclipse Testing Framework can be a real pain. I’ve tried to provide some help in previous posts. But one thing I haven’t addressed is how to properly set up a unit test environment.

The first question you might have is what is a test environment and why do I need one?. Well the short answer is that the Eclipse Testing Framework has a set of plug-ins it needs to run. The complete set of necessary plug-ins I refer to as a test environment. Yes, I just made this up, but it works for me.

In almost all cases, a test environment is composed of three things:

  1. A complete copy of the Eclipse SDK.
  2. The Eclipse Testing Framework.
  3. Your code. This includes both your production plug-ins along with any plug-ins or fragments containing unit tests.
I prefer to create this test environment on the fly during the build process. This is much cleaner than polluting a version of Eclipse that you use for development or even the instance that you use to run PDE Build. So my first tip:

Always create a test environment from scratch every time you run your unit tests. Create a new directory, add the Eclipse SDK, the ETF, and finally your own compiled plug-ins.

It’s also important to create the test environment in the correct way. The biggest mistake people make is to attempt to copy the Eclipse installation that exists on their machine. The main reason this is a problem is that you can’t be running that instance of Eclipse during the copy operation. If you do, you will probably get errors indicating that files are locked and cannot be copied to the test environment. Another problem is that a previously run instance of Eclipse will have a ton of metadata and config info associated with it. Copying all of this will seriously slow down your build and can potentially complicate the running of JUnits. So my second tip is:

Always start the creation of your test environment by extracting an archived Eclipse SDK of the appropriate version.

Hopefully these tips will help make it somewhat easier to use the Eclipse Testing Framework. It’s really not so bad, once you get things set up properly.

2 Responses to Creating a test environment for the Eclipse Testing Framework

  1. garyt says:

    Also for fun try clicking on the ‘JUnit Support in Eclipse’ in ‘Eclipse Testing Framework ‘ ( link above

  2. […] Updated PDE Build and Test Example I’ve just spent some time updating my example showing how to set up PDE Build and the Eclipse Testing Framework. I’ve generally cleaned things up and I’m now creating the test environment in the correct way. […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: