question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Skip test if its data provider provides no data

See original GitHub issue

TestNG Version

TestNG version 7.4.0

Expected behavior

Some message should be display so end user can usderstand what is the problem

Actual behavior

I get the blank output

Is the issue reproducible on runner?

[X] TestNG

Test case sample

I try to execute the simple test case which call dataProvider and this dataProvider has return type as Iterator<Object[]>,i know this return type is not accept by @DataProvider method but after execute the below program i get the blank output nothing is display in console,i accept at least message like the dataProvider is not exist, please refer below program.

public class Practice {


  @Test(dataProvider = "NotWorking")
  public void testCase(Object[] obj) {
    System.out.println(obj[0]);
    System.out.println(obj[1]);
  }

  @DataProvider(name = "NotWorking")
  public Iterator<Object[]> dataProvider2() {
    List<Object[]> obj = new ArrayList<Object[]>();
    Object[] obj1 = new Object[2];
    obj1[0] = new String("First_Object_First_value");
    obj1[1] = new String("First_Object_Second_value");
    Object[] obj2 = new Object[2];
    obj2[0] = new String("Second_Object_First_value");
    obj1[1] = new String("Second_Object_Second_value");
    Iterator<Object[]> itr = obj.iterator();
    return itr;
  }
}

i get the below output for above code,

[RemoteTestNG] detected TestNG version 7.4.0
===============================================
Default test
Tests run: 1, Failures: 0, Skips: 0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11

github_iconTop GitHub Comments

1reaction
juherrcommented, May 28, 2021

But testng at least provide message like this test method does not get any data so it was not execute

That’s an excellent idea!

0reactions
krmahadevancommented, Oct 5, 2021

@juherr

a data provider either returns an Iterator on an empty collection or

We have a proper warning message for this, but its the logger that is goofing up things for us. Our customised logger by default sets the log levels for every logger instance to WARN (3). And we are logging the problem at an INFO level.

https://github.com/cbeust/testng/blob/54329910b9b729b836620aafe926e58cbc4a7dc7/testng-core/src/main/java/org/testng/internal/Parameters.java#L803-L809

So we should be doing a few things here.

  1. Consider implementing https://github.com/cbeust/testng/issues/2646 so that a user can basically work with configuring the logger in a much more easier way. TestNG logging has the following problems:
    1. Its custom written
    2. Its confined to ONLY console logging
    3. Lacks documentation (I think we can fix this)
  2. As a temporary fix for this problem, maybe change the logging level from INFO to WARN for the above code in question.

I am going to raise a PR which implements (2) and a separate PR which addresses (1)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can I have TestNG fail/skip if the DataProvider provides no ...
The answer is yes...we can check the data provider some tricky we can use it...
Read more >
Can I have TestNG fail/skip if the DataProvider provides no ...
If my TestNG DataProvider has some logic in it, but then it results in an empty Object[][] , I would like TestNG to...
Read more >
Fail instead of Skip a Test when TestNG's DataProvider throws ...
A quite tricky problem I have been faced with was a failing TestNG-DataProvider which threw an exception because of corrupt test data.
Read more >
Skip Exception Test in TestNG - Selenium Easy
In TestNG, @Test(enabled=false) annotation is used to skip a test case if it is not ready to test. We don't need to import...
Read more >
Testing in Java & JVM projects - Gradle User Manual
If you don't want to use test class detection, you can disable it by setting the scanForTestClasses property on Test to false ....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found