For a research I\'m doing, I\'m in need of capturing the result status (Passed/Failed) after running the test method (@Test), from @AfterMethod.
I have been using the im
just do it:
public class stacktest {
@Test
public void teststackquestion() {
boolean actual = true;
boolean expected = false;
Assert.assertEquals(actual, expected);
}
@AfterMethod
public void afterMethod(ITestResult result)
{
try
{
if(result.getStatus() == ITestResult.SUCCESS)
{
//Do something here
System.out.println("passed **********");
}
else if(result.getStatus() == ITestResult.FAILURE)
{
//Do something here
System.out.println("Failed ***********");
}
else if(result.getStatus() == ITestResult.SKIP ){
System.out.println("Skiped***********");
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
The TestListenerAdapter
has methods for each of those situations (success, skipped, failure). My suggestions is to make your own listener like this.
public class MyTestResultListener extends TestListenerAdapter {
@Override
public void onTestFailure(ITestResult result) {
// do what you want to do
}
@Override
public void onTestSuccess(ITestResult result) {
// do what you want to do
}
@Override
public void onTestSkipped(ITestResult result) {
// do what you want to do
}
}
Then add your listener to the test class.
@Listeners(MyTestResultListener.class)
public class MyTest {
// your tests
}