public class

PaxExam

extends Object
implements IHookable IMethodInterceptor ISuiteListener
java.lang.Object
   ↳ org.ops4j.pax.exam.testng.listener.PaxExam
Known Direct Subclasses

Class Overview

TestNG driver for Pax Exam, implementing a number of ITestNGListener interfaces. To run a TestNG test class with Pax Exam, add this class as a listener to your test class:




 @Listeners(PaxExam.class)
 public class MyTest {

     @BeforeMethod
     public void setUp() {
     }

     @AfterMethod
     public void tearDown() {
     }

     @Test
     public void test1() {
     }
 }
 
In OSGi and Java EE modes, Pax Exam processes each test class twice, once by test driver and then again inside the test container. The driver delegates each test method invocation to a probe invoker which excutes the test method inside the container via the probe.

It would be nice to separate these two aspects and handle them in two separate listeners, but TestNG has no way to override or disable the listener annotated on the test class.

TestNG provides a listener callback for configuration methods, but it does not let us intercept them. For this reason, we use an ugly reflection hack to disable them when running under the driver and to make sure they get executed inside the test container only.

Dependencies annotated by javax.inject.Inject get injected into the test class in the container (OSGi and Java EE modes) or by the driver (CDI mode).

Summary

Constants
String PAX_EXAM_SUITE_NAME
Public Constructors
PaxExam()
Public Methods
List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context)
Callback from TestNG which lets us manipulate the list of test methods in the suite.
void onFinish(ISuite suite)
Called by TestNG after the suite has finished.
void onStart(ISuite suite)
Called by TestNG before the suite starts.
void run(IHookCallBack callBack, ITestResult testResult)
Callback from TestNG which lets us intercept a test method invocation.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.testng.IHookable
From interface org.testng.IMethodInterceptor
From interface org.testng.ISuiteListener

Constants

public static final String PAX_EXAM_SUITE_NAME

Constant Value: "PaxExamInternal"

Public Constructors

public PaxExam ()

Public Methods

public List<IMethodInstance> intercept (List<IMethodInstance> methods, ITestContext context)

Callback from TestNG which lets us manipulate the list of test methods in the suite. When running under the driver and using a probe invoker, we now construct the test addresses to be used be the probe invoker, and we sort the methods by class to make sure we can fire beforeClass and afterClass events later on.

For some reason, TestNG invokes this callback twice. The second time over, we return the unchanged method list.

public void onFinish (ISuite suite)

Called by TestNG after the suite has finished. When running in the container, this is a no op. Otherwise, we stop the reactor.

Parameters
suite test suite

public void onStart (ISuite suite)

Called by TestNG before the suite starts. When running in the container, this is a no op. Otherwise, we create and stage the reactor.

Parameters
suite test suite

public void run (IHookCallBack callBack, ITestResult testResult)

Callback from TestNG which lets us intercept a test method invocation. The two cases of running in the container or under the driver are handled in separate methods.