cbeust/testng — Issue #128: Using Object[] and Method as parameters for a test in a certain order yields an IllegalArgumentException, citing a type mismatch.
Author: leef590
Created: 2011-11-10 06:12:10+00:00
State: open

BUILD: Eclipse plugin 6.3.0.20111017_2337

DESCRIPTION:
Two data providers that provide two parameters are defined. The first data provider provides a java.lang.reflect.Method as the first parameter and an Object array as the second. The second data provider reverses the order of the parameters.

One empty test is defined to use the first data provider. Another empty test is defined to use the second data provider.

Run this test.

The code is defined below:

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import java.lang.reflect.Method;

public class TestNGBug
{
@DataProvider(name = "methods")
public Object[][] getMethods() throws NoSuchMethodException
{
return new Object[][]{
new Object[]{String.class.getMethod("toString"), new Object[0]},
};
}

@Test(dataProvider = "methods")
public void testInvokeRemote(Method param1, Object[] param2) throws Exception
{
// This fails with: java.lang.IllegalArgumentException: argument type mismatch
}

@DataProvider(name = "methods2")
public Object[][] getMethods2() throws NoSuchMethodException
{
return new Object[][]{
new Object[]{new Object[0], String.class.getMethod("toString")},
};
}

@Test(dataProvider = "methods2")
public void testInvokeRemoteReversed(Object[] param1, Method param2) throws Exception
{
// This works.
}
}

EXPECTED RESPONSE:
The order of parameters that a test method accepts are irrelevant to the results of that test.

OBSERVED RESPONSE:
The first test (with parameter types Method, Object[]) fails with an IllegalArgumentException, citing a type mismatch.

The second test (with the same parameter types in reverse order) passes without incident.

REPRO RATE: 10/10