return 类型 Array[Array[Int]] 的 Scala TestNG @DataProvider 错误(?)

Scala TestNG @DataProvider bug(?) with return type Array[Array[Int]]

此示例 (How to create TestNG DataProvider out of numbers in scala?) 适用于我的设置。

但是,如果我将其更改为以下,则会跳过测试。

@DataProvider(name = "numbersRandomRange")
def numbersRandomRange(): Array[Array[Int]] = { 
  Array(Array[Int](100, 150))
}

@Test(dataProvider = "numbersRandomRange")
def testNumbersRandomRange(min: Int, max: Int) {
  // do something here.
}

对我来说一点都不重要。但是有人可以阐明 Array[Array[Int]]Array[Array[Any]] 的幕后情况吗?

虽然我不练习 Scala 本身,但在我看来不同之处在于 TestNG expects an Object[][] as the return type of the @DataProvider

The Data Provider method can return one of the following two types:

  • An array of array of objects (Object[][]) where the first dimension's size is the number of times the test method will be invoked and the second dimension size contains an array of objects that must be compatible with the parameter types of the test method. This is the cast illustrated by the example above.
  • An Iterator<Object[]>. The only difference with Object[][] is that an Iterator lets you create your test data lazily. TestNG will invoke the iterator and then the test method with the parameters returned by this iterator one by one. This is particularly useful if you have a lot of parameter sets to pass to the method and you don't want to create all of them upfront.

并且当您指定

def numbersRandomRange():Array[Array[Any]] 

仍被解释为Object[][]

也应如此
def numbersRandomRange():Array[Array[Object]]

因此,在您的情况下,您也应该将其包装为 Object[][] / Array[Array[Object]].