An Automated OSGi Test Runner

Home  >>  Eclipse  >>  An Automated OSGi Test Runner

An Automated OSGi Test Runner

On July 4, 2013, Posted by , In Eclipse,JUnit,OSGi, By ,, , With 2 Comments

Among my fellow team members, I was known for notoriously forgetting to maintain the (JUnit) test suite. I just can’t get this extra step of manually adding a test to a suite into my fingers. Fortunately, there are continuous integration servers that collect tests by a naming pattern. If one of the orphan tests I introduced fails, it stands out there.

To make up for that, I created an (almost) maintenance-free test runner. While there is such thing already for plain JUnit tests, I couldn’t find something similar for OSGi tests.

When having multiple bundles you usually have a master test suite that aggregates all per-bundle test suites. To use the BundleTestSuite, just replace your master test suite like this:

@RunWith( BundleTestSuite.class )
@TestBundles( { "org.example.bundle1", "org.example.bundle2" } )
public class MasterTestSuite {

The RunWith annotation tells JUnit to use the BundleTestSuite test runner. This test runner then evaluates the TestBundles annotation and executes the tests from all bundles whose symbolic names are listed there. If you create a new bundle, add its name to the TestBundles list and all test that it (or its fragments) contains will be picked up. A test class is currently identified by its name. All classes whose name ends with ‘Test’ are considered test classes.

A side effect of collecting the tests reflectively is that you can remove all workarounds (Eclipse-ExtensibleAPI and the like) to make tests within fragments visible to the outside.

When tests are run in Eclipse as PDE JUnit Tests the bundle layout differs from bundles that are packaged regularly. The BundleTestSuite considers this and works around a bug in Equinox while collecting tests. Unfortunaltely, this issue also affects Tycho. Currently, the BundleTestSuite can’t be run with Tycho so that you’ll have to stay with the surefire include/exclude directives for now.

The code is available under the Eclipse Public License and hosted on GitHub. The latest stable version can be obtained from this p2 repository:

In the meanwhile (since 2014-11-12), Frank has enhanced the BundleTestSuite. There is now an extra annotation that lets you filter the tests to be run with regular expressions.

This little tool has proven useful in some projects for a while already. Thus, I thought it might help you as well. If you have any feedback whatsoever, please leave a comment or file an issue.

 Testing with JUnit

Testing with JUnit Book

Testing with JUnit is one of the most valuable skills a Java developer can learn. No matter what your specific background, whether you’re simply interested in building up a safety net to reduce regressions of your desktop application or in improving your server-side reliability based on robust and reusable components, unit testing is the way to go.

Frank has written a book that gives a profound entry point in the essentials of testing with JUnit and prepares you for test-related daily work challenges.

Learn more...

Follow me

Rüdiger Herrmann

Routined programmer, team lead, presenter, blog writer, and convinced open source contributor with two decades experience in the field.

Strong focus on quality backed up by agile methods like test driven development, modularization, pair programming, clean code, continuous integration.

Specialized in Java with JEE, REST, OSGi, RCP, RAP and building developer tools based on the Eclipse IDE (or any other platform if an opportunity arises).
Follow me

Latest posts by Rüdiger Herrmann (see all)

2 Comments so far:

  1. Jesper S. Møller says:

    This is funny – by reading this post, I just realized I forgot to add the tests in bug 406973 to the suite. Thanks!

Leave a Reply

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