This example (How to create TestNG DataProvider out of numbers in scala?) works for me with my setup.
However, if I change it to below, the test is skipped.
@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.
}
Not critical at all for me. But can someone shed light on what is going on under the hood with Array[Array[Int]]
versus Array[Array[Any]]
?
Though I do not practice Scala as such , but the difference seems to me to be that 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 withObject[][]
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.
and when you specify
def numbersRandomRange():Array[Array[Any]]
it is still interpreted as Object[][]
, the same should hold for
def numbersRandomRange():Array[Array[Object]]
So, in your case as well you should wrap it as Object[][]
/ Array[Array[Object]]
.