When a test case execution fails, we need to execute some clean up scripts (It could be something that helps the next test case to start executing smoothly).
The best practice to keep this clean up script is at test case tear down method of suite as this will be common/generic to all the test cases present in the suite.
So its important to know the status of test case execution whether it passed or failed to determine what to do next.
Test case execution status can not be determined programatically at test suite level.
This is because the tear down method i.e @AfterTestCase method do not get to know the context of testcase. That method do not simply accept the TestCaseContext parameter.
Test case execution status can be determined at TestListener level.
But the TestListener is common to all different test suites in the project, so anything you keep there will be applicable to all test suites. we need test suite specific clean up scripts.
Suggestion:
Can we have a TearDownTestCase method available at Test Suite, where we can get the TestCaseContext info
@TearDownTestCase(skipped = false) // Please change skipped to be false to activate this method.
def tearDownTestCase(TestCaseContext testCaseContext) {
def testCaseStatus = testCaseContext.getTestCaseStatus();
if(testCaseStatus.equals(“FAILED”))
{
// do something
}
else
{
//do something else
}
}
Please see this link discussion for some additional info here
Thakns