why does TestNG keep skipping my tests?

2,244 views
Skip to first unread message

Todd Bradley

unread,
Aug 7, 2015, 5:09:25 PM8/7/15
to testng...@googlegroups.com
I'm running into a situation where once a @BeforeMethod method throws a SkipException to skip a test, all subsequent test methods are also skipped. I simplified my problem down to a reproducible test case. Is this behavior by design? What am I doing wrong?


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() {

}


}



Here's the output when I run it:

[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


Cédric Beust ♔

unread,
Aug 7, 2015, 5:19:30 PM8/7/15
to testng...@googlegroups.com

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.


-- 
Cédric


--
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.

Todd Bradley

unread,
Aug 10, 2015, 12:24:46 PM8/10/15
to testng...@googlegroups.com
OK, thanks. I appreciate the quick response.

Alexander Poulikakos

unread,
Aug 10, 2015, 3:11:01 PM8/10/15
to 'Veit Guna' via testng-users

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



---- Todd Bradley skrev ----
Reply all
Reply to author
Forward
0 new messages