public class PaxExam extends Object implements org.testng.ISuiteListener, org.testng.IMethodInterceptor, org.testng.IHookable
@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).
| Modifier and Type | Field and Description |
|---|---|
static String |
PAX_EXAM_SUITE_NAME |
| Constructor and Description |
|---|
PaxExam() |
| Modifier and Type | Method and Description |
|---|---|
List<org.testng.IMethodInstance> |
intercept(List<org.testng.IMethodInstance> testMethods,
org.testng.ITestContext context)
Callback from TestNG which lets us manipulate the list of test methods in the suite.
|
void |
onFinish(org.testng.ISuite suite)
Called by TestNG after the suite has finished.
|
void |
onStart(org.testng.ISuite suite)
Called by TestNG before the suite starts.
|
void |
run(org.testng.IHookCallBack callBack,
org.testng.ITestResult testResult)
Callback from TestNG which lets us intercept a test method invocation.
|
public static final String PAX_EXAM_SUITE_NAME
public void onStart(org.testng.ISuite suite)
onStart in interface org.testng.ISuiteListenersuite - test suitepublic void onFinish(org.testng.ISuite suite)
onFinish in interface org.testng.ISuiteListenersuite - test suitepublic void run(org.testng.IHookCallBack callBack,
org.testng.ITestResult testResult)
run in interface org.testng.IHookablepublic List<org.testng.IMethodInstance> intercept(List<org.testng.IMethodInstance> testMethods, org.testng.ITestContext context)
For some reason, TestNG invokes this callback twice. The second time over, we return the unchanged method list.
intercept in interface org.testng.IMethodInterceptorCopyright © 2006–2015 OPS4J - Open Participation Software for Java. All rights reserved.