Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@ParameterizedTest with @MethodSource are not supported. #51

Closed
michael-simons opened this issue Jun 15, 2021 · 2 comments · Fixed by #59
Closed

@ParameterizedTest with @MethodSource are not supported. #51

michael-simons opened this issue Jun 15, 2021 · 2 comments · Fixed by #59
Labels
bug Something isn't working junit-support Related to JUnit Support project
Milestone

Comments

@michael-simons
Copy link

A parameterized tests with an @MethodSource like this

import java.util.stream.Stream;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

class App2Test {

	enum Things {
		A, B, C
	}

	@ParameterizedTest
	@MethodSource("aMethod")
	void functionNameSanityCheck(Things thing) {

		Assertions.assertNotNull(thing);
	}

	private static Stream<Arguments> aMethod() {
		return Stream.of(
			Arguments.of(Things.A),
			Arguments.of(Things.B),
			Arguments.of(Things.C)
		);
	}
}

fails with

Failures (1):
  JUnit Jupiter:App2Test:functionNameSanityCheck(Things)
    MethodSource [className = 'org.graalvm.buildtools.example.App2Test', methodName = 'functionNameSanityCheck', methodParameterTypes = 'org.graalvm.buildtools.example.App2Test$Things']
    => org.junit.platform.commons.JUnitException: Failed to find a no-argument constructor for ArgumentsProvider [org.junit.jupiter.params.provider.MethodArgumentsProvider]. Please ensure that a no-argument constructor exists and that the class is either a top-level class or a static nested class
       org.junit.jupiter.params.ParameterizedTestExtension.instantiateArgumentsProvider(ParameterizedTestExtension.java:110)
       java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
       java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
       java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1655)
       java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
       [...]
       Suppressed: org.junit.platform.commons.PreconditionViolationException: Configuration error: You must configure at least one set of arguments for this @ParameterizedTest
         org.junit.platform.commons.util.Preconditions.condition(Preconditions.java:281)
         org.junit.jupiter.params.ParameterizedTestExtension.lambda$provideTestTemplateInvocationContexts$6(ParameterizedTestExtension.java:94)
         java.util.stream.AbstractPipeline.close(AbstractPipeline.java:323)
         java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:271)
         [...]
     Caused by: java.lang.NoSuchMethodException: org.junit.jupiter.params.provider.MethodArgumentsProvider.<init>()
       java.lang.Class.getConstructor0(DynamicHub.java:3349)
       java.lang.Class.getDeclaredConstructor(DynamicHub.java:2553)
       org.junit.platform.commons.util.ReflectionUtils.newInstance(ReflectionUtils.java:488)
       org.junit.jupiter.params.ParameterizedTestExtension.instantiateArgumentsProvider(ParameterizedTestExtension.java:102)
       [...]

Applies to 0.9.0 and 0.9.1-SNAPSHOT, tested with GraalVM 21.1.0 JDK 11 in the Maven examples project.

@sbrannen
Copy link
Collaborator

This is closely related to #50.

See #50 (comment) for an explanation.

@sbrannen
Copy link
Collaborator

See also #54

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working junit-support Related to JUnit Support project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants