mercredi 17 mars 2021

JUnit Test - ParameterizedTests - 'No implicit conversion of type java.lang.Integer to type [Ljava.lang.Integer;'

Using JUnit5. This doesn't seem to be behaving correctly to me, I'm likely missing something.

    @ParameterizedTest
    @MethodSource
    void testFunc(Integer arr []) {
        for(Integer i : arr){
            System.out.print(i + " ");
        }
        System.out.println("\n");
    }

    static Stream<Arguments> testFunc() {
        return Stream.of(
                Arguments.of(new Integer [] {12, 42, 52, 1234, 12, 425, 4}),
                Arguments.of(new Integer [] {12, 42, 52, 1234, 12, 425}),
                Arguments.of(new Integer [] {12})
        );
    }

Produces the error:

org.junit.jupiter.api.extension.ParameterResolutionException: Error converting parameter at index 0: No implicit conversion to convert object of type java.lang.Integer to type [Ljava.lang.Integer;

I've also tried the above code using int instead of Integer, but this works correctly.

This works with no error:

    public static void main(String args[]){
        test(new Integer []{12, 42, 52, 1234, 12, 425, 4});
    }

    static void test(Integer[] arr) {
        for(Integer a : arr){
            System.out.println(a);
        }
    }

Aucun commentaire:

Enregistrer un commentaire