java 8 - TestNG data provider with folder contents using lambda -
i want give list of file names through testng data provider, 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 point can build object[][] folder contents, 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] @ org.testng.internal.reflect.dataprovidermethodmatcher.getconformingarguments(dataprovidermethodmatcher.java:52)
...
it looks me @test
method using data provider accepting file names string
data provider providing file
object , breaking.
you have 2 options:
- you change
@test
method acceptfile
object instead ofstring
. (or) - you change data provider start providing absolute paths of
file
objects instead offile
object. i.e., change.map(filename -> new object[] { filename })
.map(filename -> new object[] { filename.getabsolutepath() })
Comments
Post a Comment