In a previous post, I provided a set of projects that you could use to get a sample build running quickly. The idea was that getting your first build running is half the battle. From that point on, you can make small, incremental changes to accomplish what you like.
A common request I’ve received, though, is to provide a similar sample build that includes the running of JUnits using the Eclipse Test Framework. Well here it is! Just download and import the sample projects, and follow the directions in the included readme.txt file.
Note: If you want to run this sample build using Eclipse 3.2, you’ll need to work around a PDE Build defect. For instructions on how to do this, check out the “Problems parsing feature file in a product build” section on the PDE Build wiki page.


Hi Laurent,
I have not tried this myself – haven’t had the time yet. If it’s not working for you it would probably be best to ask questions on the Bugzilla entry. I’m definitely interested to hear if you get this working or not, so please keep me posted.
— Patrick
Patrick,
I wasn’t thinking when trying the fix. I was only using the newer eclipse test framework zip. I would also need to move to the newer SDK in order to get this to work (but I can’t move up, for other reasons).
Hi Patrick,
Thanks for this article. It was very helpful. I tried the new eclipse Testing framework(3.6M4) with my JUnit4 test case and it was working.
Could you perhaps give me some suggestion on how to execute JUnit Plug-in tests from headless Build?
Thanks in advance.
Stefanko
Hi Stefanko,
Unit tests are kicked off through Ant targets and must be run in a properly configured test environment. A sample Ant script can be downloaded via the link in the post, and I describe how to set this a test environment here:
http://www.modumind.com/2008/08/01/creating-a-test-environment-for-the-eclipse-testing-framework/
If these don’t answer your question, please feel free to clarify what you need to know.
— Patrick
Hi Patrick
Thank you for your quick reply. My question wasn’t enough clear, sorry for it.
I can run my tests from headless build but only as JUnit Tests, but not as JUnit Plug-in Tests. In the Eclipse IDE if I right click on test file there are two options in the ‘Run As’ popup menu:
1. JUnit Test
2. JUnit Plug-in Test
So my question is how to execute my test as a ‘JUnit Plug-in Test’ from headless build?
Another problem is that I have some plug-in relative file paths referenced from my JUnit tests. These relative refernces are working correctly if I run the JUnit test from eclipse IDE, but they are not correctly resolved when I run the same test from headless build.
Would you be so kind as to write me some hint how to solve these problems?
Thanks in advance.
Stefanko
Hi Stefanko,
The Eclipse Testing Framework is specifically meant to run like ‘JUnit Plug-in Test’ in the IDE. It basically runs your unit tests inside of an OSGi framework. Again, setting this up is complex and I would refer you to the sample projects that can be downloaded here. The tests that run as part of the sample are running as plug-in tests, and you should be able to modify the sample to build and test your own plug-ins.
As far as relative file paths are concerned, what are they relative to? Or maybe a better way to approach this is to tell me what you’re trying to achieve with the paths. There are various OSGi and RCP API calls to manage storage locations depending on what you’re trying to do.
— Patrick
Hi Patrick,
Thank you for your quick reply again and excuse my disturbing you again. So I am using your sample for my Headless build process, but some part of the Eclipse Testing Framework side wasn’t clear . Now I understand it, thank you very much.
For example I have a JUnit test where I use a data file from a ‘res’ folder under the plug-ins root folder and I reference to it the following way:
new File(“res/TestData.txt”)
If I run this test from the IDE it works fine, but when I execute it from the headless build the path cannot be resolved.
I receive the following message:
error message=”Source ‘res\TestData.txt’ does not exist” type=”java.io.FileNotFoundException”
So do you have any suggestion how to reference plug-in relatively to this data file?
Thanks in advance.
Stefanko
Hi Stefanko,
To get access to a resource inside of your bundle, it’s best to do something like:
Bundle bundle = Platform.getBundle(“com.mybundle.id”);
URL url = bundle.getEntry(“path-to-resource”);
The getEntry method takes a path relative to the root of your bundle. In your case this would be “res/TestData.txt”.
Hope this helps,
— Patrick
Hi Patrick,
Thank you very much, and sorry for not replying earlier.
It was a great help. That’s solved my problem.
Stefanko
Hi Patrick,
Thank you for this article which is very helpful.
I have errors while executing your instructions :
pde-build:
[java] java.lang.NoClassDefFoundError: org/eclipse/equinox/launcher/Main
[java] Caused by: java.lang.ClassNotFoundException: org.eclipse.equinox.launcher.Main
[java] at java.net.URLClassLoader$1.run(Unknown Source)
[java] at java.security.AccessController.doPrivileged(Native Method)
[java] at java.net.URLClassLoader.findClass(Unknown Source)
[java] at java.lang.ClassLoader.loadClass(Unknown Source)
[java] at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
[java] at java.lang.ClassLoader.loadClass(Unknown Source)
[java] at java.lang.ClassLoader.loadClassInternal(Unknown Source)
[java] Could not find the main class: org.eclipse.equinox.launcher.Main. Program will exit.
[java] Exception in thread “main”
[java] Java Result: 1
Have you got any idea of the source of the problem?
Thank you for all.
This error usually occurs when the launcher jar cannot be located in the java target. Check the eclipseLocation property to make sure it points to a valid Eclipse installation and also check the version of the launcher bundle specified in the build.properties. If this doesn’t eliminate the exception, let me know and we can dig a little further.
— Patrick
Hi Patrick!
Thank you very much for your quick reply.
You was right. The eclipselocation was not pointing to a valid Eclipse installation.
The build is now successful but the test process takes a very very long time (hours). After many hours it is still at the following step :
[java] [zip] Building zip: c:\helloworld-build\features\org.eclipse.pde.build.container.feature\org.eclipse.pde.build.container.feature_1.0.0.log.zip
[java] [delete] Deleting directory c:\helloworld-build\features\org.eclipse.pde.build.container.feature\feature.temp.folder
[java] [unzip] Expanding: c:\helloworld-build\features\org.eclipse.pde.build.container.feature\org.eclipse.pde.build.container.feature_1.0.0.log.zip into c:\helloworld-build\I.HelloWorld\compilelogs
[java] BUILD SUCCESSFUL
[java] BUILD SUCCESSFUL
[java] Total time: 3 minutes 11 seconds
test:
[unzip] Expanding: c:\helloworld-build-target\eclipse-SDK-3.4.1-win32.zip into c:\helloworld-build\test
[unzip] Expanding: C:\Java\workspaces\Exemples\com.rcpquickstart.helloworld.build-and-test\eclipse-test-framework-3.4.1.zip into c:\helloworld-build\test
[unzip] Expanding: c:\helloworld-build\I.HelloWorld\HelloWorld-win32.win32.x86.zip into c:\helloworld-build\test
[move] Moving 50 files to c:\helloworld-build\test\eclipse
[instr] processing instrumentation path …
So i have not the test-results.xml file which interest me the most…
Have you got any idea of what’s happening?
Thank you for all….
It appears that the process is hanging on the EMMA instrumentation. Have you verified that the EMMA libraries are available? They should be in your jre/lib/ext directory.
If EMMA is running, I’m not sure why the process is hanging at this point. Perhaps there is some issue with the EMMA instrumentation process itself?
— Patrick
Hi Patrick,
I have one more question. Is there any possibilities for that if I would like to see a build failed status when any of the JUnit tests fails? Currently I get a build failed state only if the build part fails but I get a build success state even when some JUnit tests fail.
Can I somehow configure headless build or ETF so that it return with failed status when a JUnit test fails?
Thanks in advance!
Stefanko
Hi Stefanko,
I’ve struggled with this as well. The only thing I came up with was to scan the JUnit output to determine if any tests failed. If you figure out a better way, I’d be very interested :-)
— Patrick
Patrick,
I seem to be getting an error in your tutorial. Any input on fixing the issue would be greatly appreciated.
pde-build:
[java] exception in thread “main” java.lang.NoClassDefFoundError: org/eclipse/equinox/launcher/Main
[java] Caused by java.lang.classnotfoundexception: org.eclipse.equinox.launcher.main
It can’t seem to find the “main” class that is necessary to run the equinox launcher.
Wes
Hi Wes,
There are only two things that affect whether the launcher class can be found:
1. eclipseLocation must point to a valid Eclipse installation.
2. The equinoxLauncherPluginVersion property must match the version of the org.eclipse.equinox.launcher bundle.
There is nothing specific to PDE Build in all of this, we’re just configuring the classpath of a regular Ant java task. If you’ve set the launcher version properly, can you double-check that eclipseLocation points to a valid Eclipse installation?
— Patrick
awesome tutorial! very helpful indeed.
Wes