You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

After developing a component of our OSGI application, we aim to test the new funcionality before integrating it. Unitary tests are a good solution to check the classes of our bundle in an isolated way, but what if we want to test how our bundle fits with the other components of our application? Well, we need a testing toolkit providing us the availibity of emulating our deployes environment, like Pax-Exam.

Pax-Exam

Pax-Exam is an automated testing framework for OSGI applications. Its main particularity is how it works. Pax-Exam starts a OSGI container, install the bundles we configure in it, and run our test classes. This methodology allows us to make assertions over many components, like the services we publish or the result of an operation. 

Integration test In OpenNaaS are developed using Pax-Exam 2.3.0. Using configuration options provided by this technology, we deploy our own platform inside the OSGI container, automating the installation of bundles and additional features. 

We will use OSPF integration test as an example to illustrate this tutorial. 

Configuring the OSGI container

Test driver and reactor strategy

An integration test is just no more than a java class with some particular annotations and methods. First of all, we have to define the driver the test will run with (in our case, JUnit driver), using the @RunWith annotation

@RunWith(JUnit4TestRunner.class)
public abstract class OSPFIntegrationTest
{
	...
}

 

As an optional parameter you can also define the reactor strategy. It determinates the behaviour of the container between test of the same and also of the rest of the classes. Available options are "AllConfinedStagedReactorFactory" (a new test container will be started and stoped for each test) and "EagerSingleStagedReactorFactory" (all configured test containers are stated before starting the first test). Default strategy is "AllConfinedStagedReactorFactory". This attribute can be confifured by the @ExamReactorStrategy annotation.

@RunWith(JUnit4TestRunner.class)
@ExamReactorStrategy(AllConfinedStagedReactorFactory.class)
public abstract class OSPFIntegrationTest
{
	...
}
Configuration options
  • No labels