Dustin N. Dustin N. - 9 months ago 64
Java Question

TestNG - How to force end the entire test suite from the BeforeSuite annotation if a condition is met

Is there a way to quit the entire test suite if a condition is met in the @BeforeSuite annotation? Maybe a way to call the @AfterSuite and bypass the entire test?

I make a database call in the @BeforeSuite. If the query returns any results, I send an email and now am wanting to kill the entire test suite.

I have tried

org.testng.Assert.fail("There are unpaid invoices");
, but neither of those terminate the entire suite. My scripts are setup to run classes in parallel and when I run the test from the test.xml file, each class tries to start and opens a window and then immediately closes it.

FYI, the drivers do not get created until the @BeforeClass or @BeforeMethod (depending on the switch I created for parallel methods or classes). So in all reality, there should never even be an attempt to open a browser window.

Answer Source

try new SkipException("message"); this will skip the tests if the provided condition is not true.