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.
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
As stated in the User Guide:
You may use
ParameterResolverextensions with@ParameterizedTestmethods. 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!
Most helpful comment
As stated in the User Guide:
Thus, when you swap your parameters, it works: