2017-08-14 56 views
0

我想通过TestNG数据提供程序给出文件名列表,因此测试可以加载每个文件。带有使用lambda的文件夹内容的TestNG数据提供程序

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

我得在那里我可以从文件夹中的内容建立对象[] []点,但TestNG的抛出异常:

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) 

...

回答

1

它看起来对我来说你使用你的数据提供者的@Test方法只接受文件名作为String,但你的数据提供者实际上是为它提供了一个File对象,那就是它的破坏。

你有两个选择:

  1. 你改变@Test方法接受一个File对象,而不是String。 (或)
  2. 您更改数据提供程序以开始仅提供File对象的绝对路径,而不是File对象。即变化.map(fileName -> new Object[] { fileName })变为.map(fileName -> new Object[] { fileName.getAbsolutePath() })
+0

谢谢!它实际上是一个Path,但这是代码的问题。 (路径 - >新对象[] {path.toString()})'' –

相关问题