ITestListener#onTestStart is called even if the @BeforeClass method fails on the same class as the test case

29 views
Skip to first unread message

Charles Capps

unread,
Jul 29, 2015, 4:04:48 PM7/29/15
to testng-users
I'm running into this problem, where it's really important that a listener's "onTestStart" does NOT execute if the configuration failed, i.e. if the @BeforeClass method failed. 

However, I am seeing that onTestStart still runs, even though in the final test report the test in question is skipped. 

For example, the code is very simple:

public class MyListener implements ITestListener {
@Override
public void onTestStart(ITestResult result) {
    System.out.printlnt("Running onTestStart...");
}
...implement the other methods...
}

public class MyTestClass {
  @BeforeClass
  public void setup() {
      throw new RuntimeException("Setup failed!");
  }  
  @Test
  public void doTest() {
     System.out.println("Executing test...");
  }


Now, this is annoying, because the listener actually opens a web browser in a remote Selenium Grid, and we don't want to waste these resources if the configuration failed!! 
Reply all
Reply to author
Forward
0 new messages