I've read a few posts about similar functionality, for example where a base class @BeforeClass failure causes all child classes to skip. This one is a little different. When a @BeforeClass in a child class fails, and a @BeforeMethod exists in a base class shared with another class all end up skipping.
Here's the minimal situation:
<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite">
<test name="Test">
<classes>
<class name="sandbox.SkipCascade1"/>
<class name="sandbox.SkipCascade2"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
package sandbox;
import org.testng.annotations.BeforeMethod;
public class SkipCascadeBase
{
@BeforeMethod
protected void failGenerator() {
}
}
package sandbox;
import org.openqa.selenium.NoSuchElementException;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class SkipCascade1 extends SkipCascadeBase
{
@BeforeClass
public void setup() {
throw new NoSuchElementException("D");
}
@Test
public void test() throws InterruptedException {
System.out.println("Success cascade1");
}
}
package sandbox;
import org.testng.annotations.Test;
public class SkipCascade2 extends SkipCascadeBase
{
@Test
public void test() throws InterruptedException {
System.out.println("Success cascade2");
}
}
In this case, the simple *existance* of the @BeforeMethod within the base class causes all further tests to skip. If I remove that @BeforeMethod, tests continue as expected. For us, this is a real pain, as we have @BeforeMethod and @AfterMethod calls which are executed for every test, which initiate and summarize logging information for each test. Because the @BeforeClass in the test fails, its logical that @BeforeMethods, even if in the base class, would skip. However its not logical that a skip generated by a child class would cause seemingly unrelated child classes to also skip, which seems to be happening because its marking these methods as "skipped".
How can we implement a @BeforeMethod and @AfterMethod in such a way that it doesn't invalidate our entire all-night test suite the moment one small test-specific @BeforeClass fails?
--
Chris