import static org.testng.Assert.assertTrue;
import java.lang.reflect.Method;
import org.testng.SkipException;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class MyTest {
@Test
public void testA() {
}
@Test
public void testB() {
}
@Test
public void testThisShouldBeSkipped() {
assertTrue(false);
}
@BeforeMethod
public void skipTestsThatShouldBeSkipped(Method method) {
System.out.println("Test method is: " + method.getName());
if (method.getName().equals("testThisShouldBeSkipped")) {
throw new SkipException("You asked me to skip you");
}
}
@Test
public void testZ() {
}
}
[TestNG] Running:
/private/var/folders/wt/05m_bxbj3h55rm2gyt6j3cxw0000gn/T/testng-eclipse-833894667/testng-customsuite.xml
Test method is: testA
Test method is: testB
Test method is: testThisShouldBeSkipped
SKIPPED CONFIGURATION: @BeforeMethod skipTestsThatShouldBeSkipped(public void MyTest.testThisShouldBeSkipped())
SKIPPED CONFIGURATION: @BeforeMethod skipTestsThatShouldBeSkipped
PASSED: testA
PASSED: testB
SKIPPED: testThisShouldBeSkipped
SKIPPED: testZ
===============================================
Default test
Tests run: 4, Failures: 0, Skips: 2
Configuration Failures: 0, Skips: 2
===============================================
===============================================
Default suite
Total tests run: 4, Failures: 0, Skips: 2
Configuration Failures: 0, Skips: 2
===============================================
[TestNG] Time taken by org.testng.reporters.XMLReporter@4e241f4e: 11 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 7 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@111c4d14: 4 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@31730d7b: 24 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@582ed819: 2 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@642a590d: 6 ms
This is by design. If a @BeforeMethod fails, all subsequent test methods that would have followed that method are marked as a skip.
Similarly, if a @BeforeClass fails, all methods on that class will skip as well.
--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
I think you can configure this from testng.xml file. Use attribute "configfailurepolicy" from either commandline or xml. See testng dokumentation: http://testng.org/doc/documentation-main.html#testng-xml
/Alex