Combination of @BeforeClass and @BeforeMethod causes "all skip" behaviour on seemingly unrelated tests

226 views
Skip to first unread message

edwolb

unread,
Nov 21, 2012, 4:49:00 PM11/21/12
to testng...@googlegroups.com
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"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<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

Krishnan Mahadevan

unread,
Nov 23, 2012, 9:56:27 AM11/23/12
to testng...@googlegroups.com
Chris,
Can you please try adding : configfailurepolicy="continue"

and see if that helps ?

configFailurePolicy - Whether TestNG should continue to execute the remaining tests in the suite or skip them if an @Before* method fails.

When I ran your code with this set to continue, I was able to see 1 test method run to completion.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"



--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/ChKeJkE9tfIJ.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

emailable-report.html

Chris

unread,
Nov 26, 2012, 1:33:04 PM11/26/12
to testng...@googlegroups.com
Thanks Krishnan, I tried it out with my test suite and it looks like it worked.  I scanned the TestNG documentation and couldn't find this feature mentioned, but I think it may be what I was looking for.  I've added it to our suites and we'll see the next time we have a configuration failure.

Thanks

--
Chris
Reply all
Reply to author
Forward
0 new messages