Integration Test with OSGi, Spring DM, and Maven



From Cytoscape 3, all modules are OSGi bundles. This means unit tests are not enough to verify the bundle is actually working or not on the OSGi framework because unit tests does not validate configuration files for Spring. To test the bundle's functionality, you need to write an integration test.

Automate Integration Test

You can integrate integration test to your build process by Maven. The following is the step-by-step instruction how to write an integration test for implementation bundles, which are actually import/export OSGi services.

Pom File

Integration test should be executed AFTER your code passes the unit tests. To run separate test suite as an integration test, you need to use maven-failsafe-plugin. You need to add the following section to your pom file:


Log4j Props

It is very hard to understand what's going on in the test process without watching log from Spring Extender. To watch log messages from Spring, you need to add file in src/test/resources/:

log4j.rootCategory=info, stdout
log4j.appender.stdout.layout.ConversionPattern=%t %p [%c] - %m%n

Test Code

Integration test code is very similar to standard JUnit test cases. To use testing framework by Spring, you need to use AbstractConfigurableBundleCreatorTests

   1 // Use IT*.java for Integration tests
   2 public class ITViewModelImpl extends AbstractConfigurableBundleCreatorTests {
   3     // Your test code
   4 }

The test class file should start with IT. Complete example code is available here:

To learn more about the Spring's testing framework, please read this document:

Configuration File for Testing

In the test, you need to import services from the target bundle and check it's actually working or not. In the following example, integration test imports two OSGi services exported by viewmodel-impl:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""
        xmlns:xsi="" xmlns:osgi=""

        <!-- Import services for testing -->
        <osgi:reference id="rootVisualLexiconServiceRef"
                interface="org.cytoscape.view.model.RootVisualLexicon" />
        <osgi:reference id="cyNetworkViewFactoryServiceRef"
                interface="org.cytoscape.view.model.CyNetworkViewFactory" />


Example project with integration test is available here:

Outdated_Cytoscape_3.0/Developer/Testing/Integration (last edited 2011-02-24 15:35:52 by PietMolenaar)

Funding for Cytoscape is provided by a federal grant from the U.S. National Institute of General Medical Sciences (NIGMS) of the Na tional Institutes of Health (NIH) under award number GM070743-01. Corporate funding is provided through a contract from Unilever PLC.

MoinMoin Appliance - Powered by TurnKey Linux