Java Reference
In-Depth Information
WARNING: BLUEPRINT AND FAST TESTS An automated test framework will gen-
erally start running tests as soon as the OSG i framework is initialized. This can
cause fatal problems when testing Blueprint bundles, because Blueprint ini-
tializes asynchronously. At the time you run your first test, half your services
may not have been registered! You may find you suffer from perplexing fail-
ures, reproducible or intermittent, unless you slow Pax Exam down. Waiting
for a Blueprint-driven service is one way of ensuring things are mostly ready,
but unfortunately just because one service is enabled doesn't mean they all
will be. In the case of the cheese test, waiting for the SpecialOffer service will
do the trick, because that's the service you're testing.
RUNNING THE TESTS
If you're using Maven, and you keep your test code in Maven's src/test/java folder,
your tests will automatically be run when you invoke the integration-test or
install goals. You'll need one of the Pax Exam containers declared as a Maven
dependency. If you're using Ant instead, don't worry—Pax Exam also supports Ant.
8.3.3
Tycho test
Although Pax Exam is a popular testing framework, it's not the only one. In particular,
if you're using Tycho to build your bundles, you're better off using Tycho to test them
as well. Tycho offers a nice test framework that in many ways is less complex than Pax
Exam.
Tycho is a Maven-based tool, but like Tycho build, Tycho test uses an Eclipse PDE
directory layout. Instead of putting your tests in a test folder inside your main bundle,
Tycho expects a separate bundle. It relies on naming conventions to find your tests, so
you'll need to name your test bundle with a .tests suffix.
Fragments and OSGi unit testing
Tools like Pax Exam will generate a bundle for your tests, but with Tycho you've got
control of your test bundle. To allow full white-box unit testing of your bundle, you may
find it helpful to make the test bundle a fragment of the application bundle. This will
allow it to share a classloader with the application bundle and drive all classes, even
those that aren't exported.
CONFIGURING A TEST FRAMEWORK
Tycho will use your bundle's package imports to provision required bundles into the
test platform. Like any provisioning that relies solely on package dependencies, it's
unlikely that all the bundles your application needs to function properly will be provi-
sioned. API bundles will be provisioned, but service providers probably won't be. It's
certain that the runtime environment for your bundle won't be exactly the same as
the server you eventually intend to deploy on.
To ensure Tycho provisions all your required bundles, you can add them to your test
bundle's manifest using Require-Bundle . (At this point, you may be remembering that
 
Search WWH ::




Custom Search