Java Reference
In-Depth Information
Table 7.1
OSGi test tool features
Test tool
JUnit 3
JUnit 4
TestNG
OSGi mocks
OSGi frameworks
OSGi profiles
Pax Exam
Future
Felix / Equinox / Knopflerfish
(multiple versions)
over 50
Spring DM
Future
Felix / Equinox / Knopflerfish
(single version only)
DA-Testing
Equinox (others planned)
In this chapter, you'll use Pax Exam from the OPS4J community, because we believe
it's a good general-purpose solution; but many of the techniques covered in this sec-
tion can be adapted for use with the other tools. One of Pax Exam's strengths is its
support for a wide range of different OSG i frameworks, which is important if you want
to produce robust portable bundles. But why is this?
7.3.2
Running tests on multiple frameworks
OSG i is a standard, with a detailed specification and a set of framework-compliance
tests. Even with all this, there can be subtle differences between implementations. Per-
haps part of the specification is unclear or is open to interpretation. On the other
hand, maybe your code relies on behavior that isn't part of the specification and is left
open to framework implementers, such as the default Thread Context Class Loader
( TCCL ) setting. The only way to make sure your code is truly portable is to run the
same tests on different frameworks. This is like the practice of running tests on differ-
ent operating systems—even though the JDK is supposed to be portable and standard-
ized, differences can exist, and it's better to catch them during development than to
fix problems in the field.
Unfortunately, many OSG i developers only test against a single framework. This
may be because they only expect to deploy their bundles on that particular implemen-
tation, but it's more likely that they believe the cost of setting up and managing multi-
ple frameworks far outweighs the perceived benefits. This is where Pax Exam helps—
testing on an extra OSG i framework is as simple as adding a single line of Java code.
Let's see how easy it to use Pax Exam. You'll continue to use Ant to run these tests,
although Pax Exam is primarily Maven-based. This means you need to explicitly list
execution-time dependencies in build.xml, instead of letting Maven manage this for
you. You can find your initial setup under chapter07/testing-example.
Look at the fw subproject; it contains a simple test class that prints out various
framework properties. The contents of this test class are shown next.
Listing 7.2 Simple container test
@RunWith(JUnit4TestRunner.class)
public class ContainerTest {
@Configuration
 
Search WWH ::




Custom Search