0

I want to give a list of file names through a TestNG data provider, so the test can load each file.

Object[][] result = Files.list(Paths.get("tst/resources/json"))
            .filter(Files::isRegularFile)
            .map(fileName -> new Object[] { fileName })
            .toArray(Object[][]::new);

I've got to the point where I can build the Object[][] from the folder contents, but TestNG throws exception:

org.testng.internal.reflect.MethodMatcherException: 
Data provider mismatch
Method: testFBTinka11InterpretJson([Parameter{index=0, 
type=java.lang.String, declaredAnnotations=[]}])
Arguments: [(sun.nio.fs.WindowsPath$WindowsPathWithAttributes)tst\resources\json\admin.json]

at org.testng.internal.reflect.DataProviderMethodMatcher.getConformingArguments(DataProviderMethodMatcher.java:52)

...

Cristian Cotoi
  • 163
  • 1
  • 7

1 Answers1

1

It looks to me that your @Test method which is using your data provider is accepting only file names as a String but your data provider is actually providing it with a File object and that is where its breaking.

You have two options:

  1. You change your @Test method to accept a File object instead of String. (or)
  2. You change your data provider to start providing only absolute paths of File objects instead of File object. i.e., Change .map(fileName -> new Object[] { fileName }) to .map(fileName -> new Object[] { fileName.getAbsolutePath() })
Krishnan Mahadevan
  • 14,121
  • 6
  • 34
  • 66
  • Thanks! It was actually a Path, but that was the issue with the code. Updated: `.map(path -> new Object[] { path.toString() })` – Cristian Cotoi Aug 16 '17 at 06:46