Junit5: ParameterResolutionException with TestInfo and Parameterized Tests

Created on 10 Jul 2017  路  3Comments  路  Source: junit-team/junit5

When trying to get the TestInfo as an argument to a parameterized test method an error is thrown. I'm attaching the pom and test java file in the simple testing project I'm seeing this with.

Archive.zip

The error being thrown when I run mvn clean test is:

org.junit.jupiter.api.extension.ParameterResolutionException: Discovered multiple competing
ParameterResolvers for parameter [org.junit.jupiter.api.TestInfo arg0] in executable [void
com.foo.FooTest.testParameterizedFoo(org.junit.jupiter.api.TestInfo,java.lang.String)]:
org.junit.jupiter.engine.extension.TestInfoParameterResolver,
org.junit.jupiter.params.ParameterizedTestParameterResolver

Most helpful comment

As stated in the User Guide:

You may use ParameterResolver extensions with @ParameterizedTest methods. However, method parameters that are resolved by argument sources need to come first in the argument list.

Thus, when you swap your parameters, it works:

@ParameterizedTest
@ValueSource(strings = {"hello", "world"})
void testParameterizedFoo(String argument, TestInfo info) {
    System.out.println(info.getDisplayName());
    System.out.println(argument);
}

All 3 comments

As stated in the User Guide:

You may use ParameterResolver extensions with @ParameterizedTest methods. However, method parameters that are resolved by argument sources need to come first in the argument list.

Thus, when you swap your parameters, it works:

@ParameterizedTest
@ValueSource(strings = {"hello", "world"})
void testParameterizedFoo(String argument, TestInfo info) {
    System.out.println(info.getDisplayName());
    System.out.println(argument);
}

Doh, somehow missed that. Sorry and thanks!

No worries!

Was this page helpful?
0 / 5 - 0 ratings