1

I have problem about unit testing using JUnit 5, namely when I run test method with parameterized annotation it fails but everything is correct, I think. it is JUnit 5 code:

@Test
@ParameterizedTest
@MethodSource("data")
public void test(int e){
    System.out.println("e = " + e);
}

private static Stream data(){
    return Stream.of(
        Arguments.of(1),
        Arguments.of(2)
    );
}

and it fails: enter image description here

, I have tried custom parameterize resolver but there comes up another error: it does not return passed value from data() function, but returns default value what is defined in resolveParameter() function in CustomParameterResolver class. How to solve this problem ?

1
  • Can you show your pom.xml? Commented Nov 6, 2020 at 12:17

1 Answer 1

2

You don't need @Test when using @ParameterizedTest as this will result in an additional execution of your test. This additional execution expects an int to be passed to the test but there is no resolver for this and hence the test fails with the exception you posted.

@ParameterizedTest
@MethodSource("data")
public void test(int e){
    System.out.println("e = " + e);
}

private static Stream data(){
    return Stream.of(
        Arguments.of(1),
        Arguments.of(2)
    );
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.