What's New?

This article summarizes the major changes between Pax Exam 2.x and Pax Exam 3.0.0.

Java EE Test Containers

Pax Exam 3 generalizes the in-container testing approach from OSGi to Java EE, offering test containers for a number of certified Java EE 6 servers (GlassFish 3, JBoss AS 7, Resin 4, TomEE), as well as test containers for CDI-only applications based on Weld SE or OpenWebBeans or web-only applications based on Tomcat 7.

Some of these test containers were derived from the jeeunit project, which is now fully superseded by Pax Exam 3.

More details:

Dependency Injection

In Java EE mode, Pax Exam performs dependency injection into test classes via CDI. In web-only mode, Spring is supported as an alternative to CDI.

OSGi Test Containers

Pax Runner Container Removed

The Pax Runner Test Container was deprecated in Pax Exam 2.4.0 and has now been removed from the code base. The Native Test Container is the preferred OSGi test container. Tests that require a separate Java VM for maximum isolation (e.g. due to classloader issues) can be run in the Forked Test Container.

Logging Configuration

Pax Exam 3 continues to use Pax Logging by default, but this can now be disabled using a configuration property pax.exam.logging = none, allowing users to provision alternative logging bundles of their own choice (e.g. SLF4J and Logback).

Server Mode

Pax Exam Server Mode is now supported by a JUnit rule and by a Maven plugin. In server mode, Pax Exam only launches and provisions an OSGi framework, without executing any tests. This mode is useful for non-embedded tests, e.g. web tests.

Configuration Property for System Timeout

The default system timeout can now be changed via a global configuration property pax.exam.service.timeout.

Detecting Unresolved Bundles

Pax Exam 3 has a configuration property pax.exam.osgi.unresolved.fail for detecting unresolved bundles and failing the test if any provisioned bundles remain unresolved.

Propagating System Properties

There is a new option propagateSystemProperty() for the Forked Test Container for propagating system properties from the driver VM to the forked VM.

Test Drivers

Overall Improvements

PerSuite Reactor Strategy

The new reactor strategy PerSuite starts and stops the test container only once for all test classes in the current project. This strategy is the default for Java EE containers.

Shared Configuration

A configuration method to be shared by multiple test classes can be factored out into a configuration factory class discovered via META-INF/services lookup.

Merged Annotations

Driver-specific annotations have been merged. The old 2.x annotations are still available but deprecated.

Test Method Name Mangling

Pax Exam 3 continues to mangle test method names when there is more than one test container or more than one configuration in the current reactor, to make test names unique. Names are no longer mangled for a single configuration in a single container, enabling users to run a single test method from a class under Maven or from their IDE.

Removed Deprecated Configuration Options

Configuration options deprecated in Pax Exam 2.4.0 have now been removed from the code base. These options were related to the deprecated Pax Runner Test Container or to specific libraries. Library options should now be replaced by user-defined composite options.

JUnit

Pax Exam's JUnit runner is now simply called PaxExam. The old org.ops4j.pax.exam.junit.JUnit4TestRunner is still available but deprecated.

Generic driver logic has been factored out into a ReactorManager class, to avoid code duplication between the JUnit and TestNG drivers.

TestNG

Pax Exam's TestNG listener is now simply called PaxExam. The old org.ops4j.pax.exam.testng.listener.ExamTestNGListener is still available but deprecated.

The TestNG driver now supports @BeforeMethod and @AfterMethod annotations, executing the annotated methods in the embedded container.

The listener is no longer published in META-INF/services to avoid conflicts with plain old TestNG tests not intended to be run under Pax Exam.