An Automated OSGi Test Runner

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: http://rherrmann.github.io/osgi-testsuite/repository

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.
 

Reference: An Automated OSGi Test Runner from our JCG partner Rudiger Herrmann at the Code Affine blog.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

JPA Mini Book

Learn how to leverage the power of JPA in order to create robust and flexible Java applications. With this Mini Book, you will get introduced to JPA and smoothly transition to more advanced concepts.

JVM Troubleshooting Guide

The Java virtual machine is really the foundation of any Java EE platform. Learn how to master it with this advanced guide!

Given email address is already subscribed, thank you!
Oops. Something went wrong. Please try again later.
Please provide a valid email address.
Thank you, your sign-up request was successful! Please check your e-mail inbox.
Please complete the CAPTCHA.
Please fill in the required fields.

Leave a Reply


one + 5 =



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy | Contact
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

Get ready to Rock!
You can download the complementary eBooks using the links below:
Close