lundi 8 octobre 2018

TestNG set test status

I have a custom reporting and assertion solution that's working exactly how I want it to, however gradle is not properly marking the tests as failed. The most simple solution to me, is simply to mark the test as failed in testNG whenever my assertions are resolved, so it will then mark it as failed in gradle. I have set the test status using this:

Reporter.getCurrentTestResult().setStatus(ITestResult.FAILURE);

But it is reverting after the @Test method is over

@Test
public void assertionsFail(){
  //Custom assertion fails
  generalAssertion(new AssertionPayload(false));
  //Let testNG know that test failed
  Reporter.getCurrentTestResult().setStatus(ITestResult.FAILURE);
  //Marked as failed here, Reporter.getCurrentTestResult() returns 2
}

@AfterMethod(alwaysRun = true)
public void afterTest(ITestResult testResult) {
  //Why is it marked as passed here? Reporter.getCurrentTestResult() returns 1

}

I confirmed at the end of the test method that the status is set to fail. However, when it reaches my @AfterTest, for some reason it is no longer set to fail, but is set to pass. Is there something simple I am missing here? Is there an easy way to simply mark a test as failed? I've looked into making a softAssert with that fails but that is really janky and not ideal.

Aucun commentaire:

Enregistrer un commentaire