This project provides classes which are common to all tests for SFMF4J implementations. It exists to make developing and testing SFMF4J implementations as easy as possible. It is declared as a test-scoped dependency by the implementation modules, and is not intended for use by applications.
Libraries which implement SFMF4J should declare this module as a test-scoped dependency.
Test classes for non-OSGi environments need only extend AbstractNonOSGiTest and implement the following methods:
Test classes for OSGi environments should extend AbstractOSGiTest and implement the following methods:
Testing your OSGi bundle with Pax Exam as part of the build process can be a bit tricky. Your bundle won't be produced until the tests have passed, so how can you test against a non-existent OSGi bundle?
Fortunately, Pax Exam can be configured to load a folder hierarchy as if it were packaged into a single file. ${project.build.outputDirectory} is perfect for this, but you'll also need to ensure there is an OSGi bundle manifest in this folder so that Pax Exam can load it. All you need to do is configure maven-bundle-plugin to generate the manifest before the tests are run:
<build> <plugins> <plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <!-- ... (version, configuration, et cetera) --> <executions> <execution> <id>bundle-manifest</id> <phase>process-classes</phase> <goals> <goal>manifest</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
Then, you can reference the exploded bundle in your OSGi test:
import com.github.sworisbreathing.sfmf4j.osgi.test.AbstractOSGiTest; import org.ops4j.pax.exam.CoreOptions; import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.util.PathUtils; public class MyOSGiTest extends AbstractOSGiTest { @Override protected Option implementationOption() { return CoreOptions.bundle("reference:file:" + PathUtils.getBaseDir() + "/target/classes"); } }