简体   繁体   中英

TestNG skips test after raising Exception in @DataProvider method

I'm a bit confused.

How can I get TestNG to report an error for a test?

// ...
@DataProvider(name = "foo")
public Object[][] provideData () {
    throw new SomeRuntimeException("Some error occurred. The test configuration "
            + "is somehow incorrect.");
}

This will just lead to test skipping. The exception doesn't even get logged. Moving this to a constructor will just get the exception logged but that's not enough...

I want a big fat error message.

At the moment, using a dedicated (self) test method does the job which at leasts shows some test failure...

Anyway, it would be nice to know how testNG's definition of an error looks like.

Thank you for any hints!

Here is the article which proposes fair set of alternatives with detailed enough explanations:

Fail instead of Skip a Test when TestNG's DataProvider throws an Exception

For me best way happened to add test for data providers and here is brief illustration of idea:

public class MyClass {

    @DataProvider(name = "my-data-provider")
    private Object [][] myProvider() {
        // ...
    }

    @Test
    public void testDataProviders() {
        Assert.assertTrue(myProvider().length > 0);
    }

    @Test
    // ... Real tests.

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM