Skip to content
Advertisement

junit 5 custom parametrized tests

I’m using Junit 5 parametrized tests with custom name as follow

JavaScript

where PARAMETERIZED_TESTS_NAME_PLACEHOLDER is defined in its own utility class

JavaScript

the problem I’m facing is that as I’m using extensively the parametrized tests, my code is cluttered by these @ParameterizedTest(name = PARAMETERIZED_TESTS_NAME_PLACEHOLDER).

so I created a custom annotation to fix this

JavaScript

but this annotation is ignored when I use it in the test cases

any help would be appreciated

Advertisement

Answer

The @ParamterizedTest annotation appears to have a retention policy of runtime suggesting it’s needed and processed at runtime. Try this config

JavaScript

It seems odd to me that this is not the default retention policy for custom annotations, see more from this post.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement