How to parameterize with String arrays in JUnit 5

后端 未结 3 2081
不思量自难忘°
不思量自难忘° 2021-02-07 14:17

I would like to write JUnit 5 parametrized test which takes string array (String[]) as a parameter:



        
3条回答
  •  执笔经年
    2021-02-07 14:49

    Use the Arguments.of() factory from org.junit.jupiter.params.provider.Arguments to wrap your arguments:

    static Stream stringArrayProvider() {
        return Stream.of(
                Arguments.of((Object) new String[]{"1", "2"}),
                Arguments.of((Object) new String[]{"1", "2", "3"})
        );
    }
    

    For details see http://junit.org/junit5/docs/current/user-guide/#writing-tests-parameterized-tests

提交回复
热议问题