Usually, when we write unit tests with debug enabled or data base tests with Hibernate show_sql property turned on, we end up with a huge output log were it's hard to see where each test case method started (or ended).
Comes to your rescue - TestExecutionListener with Spring TestContext Framework. By simply implementing the TestExecutionListener interface, you can add various functionalities to your test cases. These customized listeners can be easily put in action by annotating your test class with @TestExecutionListeners and providing your implementation to the framework
Here's a simple implementation for outputting additional information to your test logs with test name (class containing your test methods) and test case you're currently running:
Comes to your rescue - TestExecutionListener with Spring TestContext Framework. By simply implementing the TestExecutionListener interface, you can add various functionalities to your test cases. These customized listeners can be easily put in action by annotating your test class with @TestExecutionListeners and providing your implementation to the framework
Here's a simple implementation for outputting additional information to your test logs with test name (class containing your test methods) and test case you're currently running:
public class ExtraInfoListener extends AbstractTestExecutionListener {
private static final Log logger = LogFactory.getLog(ExtraInfoListener.class);
@Override
public void beforeTestMethod(final TestContext testContext) throws Exception {
final String testName = testContext.getTestInstance().getClass().getSimpleName();
final String testCaseName = testContext.getTestMethod().getName();
logger.info("******************************************************************");
logger.info(" Running test case: " + testName + "#" + testCaseName);
logger.info("******************************************************************");
super.beforeTestMethod(testContext);
}
}
No comments:
Post a Comment