samedi 27 octobre 2018

Is it possible to catch an Assertion Error and still fail the test?

I'm trying to Catch an Assertion Error and still Fail the test but when I try the approach below my TestNG test will Pass.

I'm thinking I could use some type of Boolean flag to keep track of the Pass or Fail and then have the Test Listener Class Pass or Fail the test based on the flag but this will cause issue when running in parallel later as the flag will need to be static.

Is there a better way to do this?

        try {
            softAssert.assertAll();
            getLogger().info("Test Passed");
        } catch (AssertionError ae) {
            getLogger().info("Test Failed");
            getLogger().info("Assertion Error: " + ae.getMessage());
            softAssert.fail("Assertion Error: " + ae.getMessage());
        }

Aucun commentaire:

Enregistrer un commentaire