Integration Test with OSGi, Spring DM, and Maven
Status
Still under construction - KeiichiroOno (8/16/2010)
Introduction
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:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <version>2.6</version> <executions> <execution> <id>integration-test</id> <goals> <goal>integration-test</goal> </goals> </execution> <execution> <id>verify</id> <goals> <goal>verify</goal> </goals> </execution> </executions> </plugin>
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 log4j.properties file in src/test/resources/:
log4j.rootCategory=info, stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout.ConversionPattern=%t %p [%c] - %m%n log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.threshold=TRACE log4j.logger.org.springframework=INFO log4j.logger.org.springframework.osgi.test=INFO
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 }
5