How can I change the status of the test which is skip before method

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How can I change the status of the test which is skip before method

Merve Yaldiz
I do some processing for pre-preparation in the @before method. When any of these actions fail, the test case is skipped. Where can I set this test case status as a fail? When I came to the @aftermethod, I set the test result to fail but my test status skip. 

When I debug, the Test Listener Adapter objects are already set as skip so result looks skipped  when reporting. How can I solve this problem ?How can I change the test result before the listener objects are set to final ? 

Can I change the test result before the result of the listener objects is set

@AfterMethod(alwaysRun = true)
public void cleanUp(ITestContext context) {

for(ITestResult result : context.getSkippedTests().getAllResults()){
result.setStatus(ITestResult.FAILURE);

                     // I already set test result as a FAILURE 
context.getFailedTests().addResult(result, result.getMethod());
context.getSkippedTests().getAllResults().remove(result);
result.getTestContext().getSkippedTests();
 
}
}

SKIPPED: helloTest
         

===============================================
    Default test
    Tests run: 1, Failures: 0, Skips: 1
    Configuration Failures: 2, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 2, Failures: 2, Skips: 0
Configuration Failures: 2, Skips: 0
===============================================

[[TestHTMLReporter passed=0 failed=0 skipped=1], org.testng.reporters.JUnitXMLReporter@59d4cd39, org.testng.remote.strprotocol.RemoteTestListener@4b34fff9, [TextReporter passed=0 failed=0 skipped=1], [ISBTestListenerAdapter passed=0 failed=0 skipped=0], org.testng.TestNG$ExitCodeListener@16aa8654, [TestListenerAdapter passed=0 failed=0 skipped=1]]

public static void runTestListeners(ITestResult tr, List<ITestListener> listeners) {
    for (ITestListener itl : listeners) {
      switch(tr.getStatus()) {
        case ITestResult.SKIP: {
          itl.onTestSkipped(tr);
          break;
        }
        case ITestResult.SUCCESS_PERCENTAGE_FAILURE: {
          itl.onTestFailedButWithinSuccessPercentage(tr);
          break;
        }
        case ITestResult.FAILURE: {
          itl.onTestFailure(tr);
          break;
        }
        case ITestResult.SUCCESS: {
          itl.onTestSuccess(tr);
          break;
        }

        case ITestResult.STARTED: {
          itl.onTestStart(tr);
          break;
        }

        default: {
          assert false : "UNKNOWN STATUS:" + tr;
        }
      }
    }
  }

Thank you for your help


--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Loading...