0

I've tests where based on some condition, I skip execution in @BeforeClass itself like -

@BeforeClass(alwaysRun = true)
public void beforeClass() {
    if (someCondition) {
            //do something
    } else {
        throw new SkipException("THESE TESTS ARE NOT INTENDED TO EXECUTE: ");
    }       
}

@BeforeMethod
public void beforeMethod() {
    // do something
}

But I run tests, skipExecution statement is executed still execution goes in method annotated with @BeforeMethod and code under it is executed which results my tests in failure instead of skip status.

Is this known bug in TestNG or issue with TestNG version? I'm using TestNG 6.9.10 version

Rub
  • 160
  • 2
  • 12
Alpha
  • 13,320
  • 27
  • 96
  • 163
  • An old post suggests that SkipException works in BeforeMethod but not in other configuration methods - https://stackoverflow.com/questions/21591712/how-do-i-use-testng-skipexception. You can also skip test methods in runtime by switching the enabled attribute of the Test annotation to false by using the IAnnotationTransformer. - http://testng.org/doc/documentation-main.html#annotationtransformers and https://stackoverflow.com/questions/33476985/how-to-skip-or-ignore-execution-of-tests-in-testng (juherr answer) – Grasshopper Dec 22 '17 at 07:01
  • Can you please try again using the latest released version of TestNG [currently it is `6.13.1`] ? I am not able to reproduce this issue with it. – Krishnan Mahadevan Dec 25 '17 at 08:35
  • Yes I also cannot reproduce it with testng 6.9.10 when I separately try it out. But it reproduces with our automation framework. Looks somewhere exception is being caught. – Alpha Dec 26 '17 at 05:38

0 Answers0