Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive report of `UnusedMethod` for methods annotated with testng's `@DataProvider` #1500

Open
dpursehouse opened this issue Feb 5, 2020 · 2 comments

Comments

@dpursehouse
Copy link
Contributor

@dpursehouse dpursehouse commented Feb 5, 2020

Description of the problem / feature request:

When a test class uses the @DataProvider annotation on a private method, error-prone reports UnusedMethod.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

This is not a completely working example, it's a redacted version of one of the classes where this occurs in my project (which is unfortunately not open source so I can't just link to the actual class), but it should show the use case. In this case the UnusedMethod would be reported for the data method.

import static org.fest.assertions.api.Assertions.assertThat;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class MyTest {
  @Test(dataProvider = "data")
  public void testInputGivesCorrectOutput(String input, String expected) throws Exception {
    // given
    MyClass objectUnderTest = new MyClass();

    // when
    String actual = objectUnderTest.get();

    // then
    assertThat(actual).isEqualTo(expected);
  }

  @DataProvider
  private static Object[][] data() {
    return new Object[][] {
      {"input-1", "output-1"},
      {"input-2", "output-2"}
    };
  }
}

What version of Error Prone are you using?

2.3.4

Have you found anything relevant by searching the web?

No. For now I am just disabling this warning.

@tom-smalls
Copy link
Contributor

@tom-smalls tom-smalls commented May 1, 2020

Same thing is happens when writing parameterized tests with @MethodSource from Junit5

@sumitbhagwani
Copy link
Contributor

@sumitbhagwani sumitbhagwani commented Jul 23, 2020

For the testng dataprovider issue, it should be fixed by #1740

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.