org.junit.jupiter.api.extension.ParameterResolutionException: No ParameterResolver registered for parameter [java.lang.String arg0] in method [void ParametrizedTest.test(java.lang.String)].
This was the code that was used to trigger the error.
import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; import java.util.stream.Stream; import static org.junit.jupiter.api.Assertions.assertTrue; public class ParametrizedTest { @Test @ParameterizedTest @MethodSource("stringProvider") void test(String string) { assertTrue(true); } public static StreamstringProvider() { return Stream.of("", null, "123"); } }
The issue is that the test method is annotated with both @Test and @ParameterizedTest. When using parameterized tests, you should only annotate your test method with @ParameterizedTest and not @Test. Removing the @Test annotation will prevent this error.
import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; import java.util.stream.Stream; import static org.junit.jupiter.api.Assertions.assertTrue; public class ParametrizedTest { @ParameterizedTest @MethodSource("stringProvider") void test(String string) { assertTrue(true); } public static StreamstringProvider() { return Stream.of("", null, "123"); } }
Thanks!
ReplyDelete