Jump to: navigation, search

Eclipse/Testing/JUnit4 Changes

< Eclipse‎ | Testing
Revision as of 11:50, 17 November 2009 by Dj houghton.ca.ibm.com (Talk | contribs) (JUnit Bundle Configuration)


This page describes steps taken to provide support for running JUnit4-style tests within the Eclipse Test Framework (ETF). Included is a brief description of why each of the main changes was made. More information about the development process can be found in the bug report. A few simple steps are required on the part of the user to run tests which require JUnit 4.x. As for JUnit 3.x tests, the Framework is fully backwards compatible.

For the duration of this page, tests that use any of the new features provided by JUnit 4.x (annotations, static imports, etc.) will be referred to as "JUnit4 tests". Tests that do not use JUnit 4's features will be referred to as "JUnit3 tests".

Test framework changes

JUnit4 Bundle Rename

Because we wanted to retain backwards compatibility of the Framework, having the org.eclipse.test bundle depend on org.junit4 simply wasn't an option. This would mean that users running with a JVM <1.5 would not be able to resolve the org.eclipse.test bundle. So it was decided that by renaming the JUnit4 bundle to "org.junit" (same as the JUnit3 bundle name), the EclipseTestRunner (ETR) could just run with the highest version of org.junit that gets resolved.

org.junit4 is now "empty", and simply re-exports the packages exported by the org.junit version 4.x bundle.

JUnit Bundle Configuration

With the JUnit 3 and 4 bundles both named org.junit, we run into a problem of backwards compatibility. Let's say that our user would like to run his/her tests that depend on org.junit and specify a version less than 4.0.0. This user has also decided to run with a Java 1.5 VM. So now the ETR will attempt to run JUnit 3 tests with the org.junit version 4.x bundle resolved. This shouldn't be a problem as JUnit4 is backwards compatible, except that the user's bundle requires JUnit <4. So we run into an issue of org.junit packages being equal but not identical; ETR is using junit.framework version 4.x but the user's bundle is bound to junit.framework version 3.x. We are still working on a solution to this problem but the result will be that all bundles in the system should resolve against the older version of JUnit... there should be no mixed-version resolution.

Loading Tests

Changes required by test bundles

If your test bundle does not contain any code which is directly dependent on a specific version of Junit (either 3 or 4), then the bundle dependency specified in your manifest file should read just "3.8.1". (for instance) This tells OSGi that you will be able to run with any version of JUnit greater than or equal to 3.8.1. (And this should work because JUnit4 is backwards compatible)

Using the test framework with JUnit3 or Junit4

Steps to run with JUnit4

  1. Run the Eclipse Test Framework with a Java 1.5+ VM
  2. Ensure that you specify that your bundle requires org.junit version 4.0.0+, either in the bundle dependencies or package imports.

Steps to run with JUnit 3

  1. Run the Eclipse Test Framework with JDK 1.4
  2. Ensure that you specify that your bundle requires org.junit version less than 4.0.0, either in the bundle dependencies or package imports.