1

while migrating from junit4 to junit5, instead of

@Parameterized.Parameters
public static Collection input() {}

I have added before all the test methods

@ParameterizedTest
@MethodSource("input")

but I am getting the error as : org.junit.jupiter.api.extension.ParameterResolutionException: No ParameterResolver registered for parameter

Any help appreciated!

Tanaya Mitra
  • 43
  • 1
  • 7
  • I think you should put your entire pom.xml and your test class in your question. I'm trying to help but wonder if your issue is reproducible. – Igor Flakiewicz Jan 21 '22 at 17:10

1 Answers1

1

Example of correct implementation of parameterized test:

//example with 2 parameters
@ParameterizedTest
@MethodSource("input")
void myTest(String input, String expectedResult) {
   //test code
}

// Make sure to use the correct return type Stream<Arguments>
static Stream<Arguments> input() {
    return Stream.of(
            Arguments.of("hello", "hello"),
            Arguments.of("bye", "bye")
            //etc
    );
}

Also make sure you are using a compatible version of junit jupiter:

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter</artifactId>
    <version>${some.version}</version>
    <scope>test</scope>
</dependency>

Also you need junit-vintage-engine dependency if you still have junit4 tests.

Igor Flakiewicz
  • 694
  • 4
  • 15
  • changed the return type of input method as: public static Stream input() { List input = new ArrayList(); } and made the return as: return Stream.of(Arguments.of(input)); In the test methods added the arguments as: @ParameterizedTest @MethodSource("input") public void testGetBlockNoByTxId(List input){} NOT WORKING – Tanaya Mitra Jan 21 '22 at 10:39
  • @TanayaMitra share your pom.xml and your test class (including imports) – Igor Flakiewicz Jan 21 '22 at 15:19
  • junit-jupiter-engine 5.7.2 junit-jupiter-params 5.7.2 @Order(1) @ParameterizedTest @MethodSource("input") public void testChannelServiceDiscovery2() throws Exception {} public static Collection input() throws Exception { List input = new ArrayList(); return input; } The same works in a different project, wondering what i am missing! – Tanaya Mitra Jan 21 '22 at 15:49
  • I recommend throwing out all your junit dependencies and just using `junit-jupiter` like in my example. Also if you are using `spring-boot-starter-test` that may contain some clashing dependencies that you may have to exclude. See https://stackoverflow.com/questions/48448331/difference-between-junit-jupiter-api-and-junit-jupiter-engine/55084036#55084036 – Igor Flakiewicz Jan 21 '22 at 15:57
  • not working...tried removing the dependencies and added only junit-jupiter – Tanaya Mitra Jan 21 '22 at 16:19
  • I'm using 5.6.0 maybe there's a bug in the version you are using? Also make sure to rebuild the project before rerunning the tests. – Igor Flakiewicz Jan 21 '22 at 17:09