Closed as not planned
Closed as not planned
Description
openedon May 25, 2023
Deliverables
- Get test method in
ParameterResolver
of parameterizedTest factory method. for example belowextensionContext.getTestMethod()
should return methodtestWithFactoryMethodWithArguments
public class MyTest {
@RegisterExtension
static final IntegerResolver integerResolver = new IntegerResolver();
@ParameterizedTest
@MethodSource("factoryMethodWithArguments")
void testWithFactoryMethodWithArguments(String argument) {
assertTrue(argument.startsWith("2"));
}
static Stream<Arguments> factoryMethodWithArguments(int quantity) {
return Stream.of(
arguments(quantity + " apples"),
arguments(quantity + " lemons")
);
}
static class IntegerResolver implements ParameterResolver {
@Override
public boolean supportsParameter(ParameterContext parameterContext,
ExtensionContext extensionContext) {
return parameterContext.getParameter().getType() == int.class;
}
@Override
public Object resolveParameter(ParameterContext parameterContext,
ExtensionContext extensionContext) {
Optional<Method> testMethod = extensionContext.getTestMethod();
boolean present = testMethod.isPresent(); //false
return 2;
}
}
}
Related issues
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment