# Apache Sling Testing PaxExam
This module is part of the [Apache Sling](https://sling.apache.org) project.
**Test support for use with Pax Exam.**
* _Sling's Karaf Features_ as `Option`s for Pax Exam (without Karaf)
* `TestSupport` with common helper methods and `Option`s
**Provided features:**
* run integration tests in a Sling instance in the same module (with the build artifact under test)
* use different versions in build (e.g. *minimal*) and tests (e.g. *latest*)
* overriding of versions
## Getting Started
Add required dependencies:
org.apache.sling
org.apache.sling.testing.paxexam
${org.apache.sling.testing.paxexam.version}
provided
org.apache.felix
org.apache.felix.framework
5.6.6
test
junit
junit
test
org.ops4j.pax.exam
pax-exam
${org.ops4j.pax.exam.version}
test
org.ops4j.pax.exam
pax-exam-cm
${org.ops4j.pax.exam.version}
test
org.ops4j.pax.exam
pax-exam-container-forked
${org.ops4j.pax.exam.version}
test
org.ops4j.pax.exam
pax-exam-junit4
${org.ops4j.pax.exam.version}
test
org.ops4j.pax.exam
pax-exam-link-mvn
${org.ops4j.pax.exam.version}
test
Configure the build artifact (*bundle*) to use in integration testing in `pom.xml`:
org.apache.maven.plugins
maven-failsafe-plugin
2.18.1
integration-test
verify
true
bundle.filename
${basedir}/target/${project.build.finalName}.jar
Add `depends-maven-plugin` when using `TestSupport#baseConfiguration()` or `SlingVersionResolver#setVersionFromProject(…)` (see below):
org.apache.servicemix.tooling
depends-maven-plugin
1.3.1
generate-depends-file
Create a test class (extend `TestSupport` to use helper methods and `Option`s) and provide a *Configuration* (`Option[]`) for Pax Exam:
@Configuration
public Option[] configuration() {
return new Option[]{
baseConfiguration(), // from TestSupport
launchpad(),
// build artifact
testBundle("bundle.filename"), // from TestSupport
// testing
junitBundles()
};
}
protected Option launchpad() {
final String workingDirectory = workingDirectory(); // from TestSupport
final int httpPort = findFreePort(); // from TestSupport
return composite(
slingLaunchpadOakTar(workingDirectory, httpPort), // from SlingOptions
slingExtensionModels(), // from SlingOptions (for illustration)
slingScriptingThymeleaf() // from SlingOptions (for illustration)
);
}
**Overriding (or adding) versions:**
SlingOptions.versionResolver.setVersion(SLING_GROUP_ID, "org.apache.sling.jcr.oak.server", "1.1.0");
using a version from project (`pom.xml`):
SlingOptions.versionResolver.setVersionFromProject(SLING_GROUP_ID, "org.apache.sling.jcr.oak.server");
**NOTE:** When using `slingLaunchpadOakTar()` or `slingLaunchpadOakMongo()` without _working directory_, _HTTP port_ and _Mongo URI_ make sure to clean up file system and database after each test and do not run tests in parallel to prevent interferences between tests.