Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 694
Doe Johnson Avatar asked May 26 '14 14:05

Doe Johnson


1 Answers

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.

}
like image 59
Roman Nikitchenko Avatar answered Oct 15 '22 10:10

Roman Nikitchenko