static List < NamedArgument > getNamedArgs ( ExtensionContext context ) { List < NamedArgument > namedArgs = new ArrayList <> ( ) ; if ( context . getTestMethod ( ) . get ( ) . getParameterCount ( ) > 0 ) { try { if ( context . getClass ( ) . getCanonicalName ( ) . equals ( METHOD_EXTENSION_CONTEXT ) ) { Field field = context . getClass ( ) . getSuperclass ( ) . getDeclaredField ( "testDescriptor" ) ; Object testDescriptor = ReflectionUtil . getFieldValueOrNull ( field , context , ERROR ) ; if ( testDescriptor != null && testDescriptor . getClass ( ) . getCanonicalName ( ) . equals ( TEST_TEMPLATE_INVOCATION_TEST_DESCRIPTOR ) ) { Object invocationContext = ReflectionUtil . getFieldValueOrNull ( "invocationContext" , testDescriptor , ERROR ) ; if ( invocationContext != null && invocationContext . getClass ( ) . getCanonicalName ( ) . equals ( PARAMETERIZED_TEST_INVOCATION_CONTEXT ) ) { Object arguments = ReflectionUtil . getFieldValueOrNull ( "arguments" , invocationContext , ERROR ) ; List < Object > args = Arrays . asList ( ( Object [ ] ) arguments ) ; namedArgs = ParameterNameUtil . mapArgumentsWithParameterNames ( context . getTestMethod ( ) . get ( ) , args ) ; } } } } catch ( Exception e ) { log . warn ( ERROR , e ) ; } } return namedArgs ; }
This is a very ugly workaround to get the method arguments from the JUnit 5 context via reflection .