I came up with the following solution:
@TestExecutionListeners( { DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class })
public class AbstractSpringContextEndpointTest extends AbstractSmockServerTest {
protected final Log logger = LogFactory.getLog(getClass());
protected ApplicationContext applicationContext;
private final TestContextManager testContextManager;
private Throwable testException;
public AbstractSpringContextEndpointTest() {
this.testContextManager = new TestContextManager(getClass());
}
//-----------------------------------------------------
// Methods taken from AbstractTestNGSpringContextTests
//-----------------------------------------------------
public final void setApplicationContext(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
@BeforeClass(alwaysRun = true)
protected void springTestContextBeforeTestClass() throws Exception {
this.testContextManager.beforeTestClass();
}
@BeforeClass(alwaysRun = true, dependsOnMethods = "springTestContextBeforeTestClass")
protected void springTestContextPrepareTestInstance() throws Exception {
this.testContextManager.prepareTestInstance(this);
}
@BeforeMethod(alwaysRun = true)
protected void springTestContextBeforeTestMethod(Method testMethod) throws Exception {
this.testContextManager.beforeTestMethod(this, testMethod);
}
public void run(IHookCallBack callBack, ITestResult testResult) {
callBack.runTestMethod(testResult);
Throwable testResultException = testResult.getThrowable();
if (testResultException instanceof InvocationTargetException) {
testResultException = ((InvocationTargetException) testResultException).getCause();
}
this.testException = testResultException;
}
@AfterMethod(alwaysRun = true)
protected void springTestContextAfterTestMethod(Method testMethod) throws Exception {
try {
this.testContextManager.afterTestMethod(this, testMethod, this.testException);
}
finally {
this.testException = null;
}
}
@AfterClass(alwaysRun = true)
protected void springTestContextAfterTestClass() throws Exception {
this.testContextManager.afterTestClass();
}
}
This works fine and my tests can now use the amazing Smock framework :)
Cheers