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 previousposts. 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:
A complete copy of the Eclipse SDK.
The Eclipse Testing Framework.
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.