Skip to content

Automatically do safe conversions of primitive types  #39

@hajo-tng

Description

@hajo-tng

In version 1.7.0 this works:

@DataProvider
public static Object[][] myDataProvider() {
    return new Object[][] {
        { 0, 0 },
        { 1, 1 }
    };
}

@Test
@UseDataProvider( "myDataProvider" )
public void testSomething( long input, long expected ) {
    // ...
}

In version 1.9.1 it results in this error, as the data provider gives an int where a long is expected:

java.lang.Error: Cannot explode 'MyTest.testSomething' using 'myDataProvider' due to: Parameter 0 is of type long but argument given is 0 of type Integer
    at com.tngtech.java.junit.dataprovider.internal.TestGenerator.generateExplodedTestMethodsFor(TestGenerator.java:46)
    at com.tngtech.java.junit.dataprovider.DataProviderRunner.generateExplodedTestMethodsFor(DataProviderRunner.java:181)
    at com.tngtech.java.junit.dataprovider.DataProviderRunner.computeTestMethods(DataProviderRunner.java:136)
    ...
Caused by: java.lang.IllegalArgumentException: Parameter 0 is of type long but argument given is 0 of type Integer
    at com.tngtech.java.junit.dataprovider.internal.DataConverter.checkIfArgumentsMatchParameterTypes(DataConverter.java:127)
    at com.tngtech.java.junit.dataprovider.internal.TestGenerator.explodeTestMethod(TestGenerator.java:112)
    at com.tngtech.java.junit.dataprovider.internal.TestGenerator.explodeTestMethod(TestGenerator.java:88)
    at com.tngtech.java.junit.dataprovider.internal.TestGenerator.generateExplodedTestMethodsFor(TestGenerator.java:44)
    ... 27 more

Unfortunately this affects a large number of data providers in our project. It would be nice to be able to continue using ints and have them automatically converted to longs.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions