junit5 icon indicating copy to clipboard operation
junit5 copied to clipboard

Support `@EnumSource`, `@CsvSource`, etc. as repeatable annotations

Open bjmi opened this issue 1 year ago • 10 comments

Given following example with types from the JDK,

@EnumSource(IsoEra.class)
@EnumSource(MinguoEra.class)
@EnumSource(HijrahEra.class)
@ParameterizedTest
void getDisplayName(Era era) {
    assertNotNull(era.getDisplayName(TextStyle.FULL, Locale.ROOT));
}

the compiler complains with:

java: org.junit.jupiter.params.provider.EnumSource is not a repeatable annotation type

It would be useful if multiple @EnumSource annotations were allowed for a single parameterized test.

My use case would be two enums that both implement the same interface that is used as the method parameter.

(Others JDK types are java.nio.file.LinkOption and java.nio.file.StandardOpenOption that implement the same java.nio.file.OpenOption.)

bjmi avatar Mar 18 '24 12:03 bjmi

Team decision: Make all @..Source annotations repeatable while making sure it makes sense for all of them.

marcphilipp avatar Mar 22 '24 11:03 marcphilipp

The functionality required to support this feature is luckily already available.

  • #1793
  • #1849

sbrannen avatar Mar 22 '24 13:03 sbrannen

@sbrannen I would like to grab this one if it's still valid

madalingiurca avatar Mar 23 '24 13:03 madalingiurca

Hi @madalingiurca,

This issue is labeled as up-for-grabs, and you are the first to volunteer.

So feel free to submit a PR!

sbrannen avatar Mar 23 '24 14:03 sbrannen

@madalingiurca Have you already started on this?

marcphilipp avatar Apr 09 '24 09:04 marcphilipp

@marcphilipp nothing apart from forking the junit5 repo, unfortunately. I'll try to find some time for it by the end of this week. If anyone else is planning to submit a PR faster, feel free to do it

madalingiurca avatar Apr 09 '24 14:04 madalingiurca

No worries! Please let us know when you start.

marcphilipp avatar Apr 12 '24 07:04 marcphilipp

@marcphilipp, I've drafted one approach in #3787.

So far, I've adapted @CSVSource annotation for repeatable capabilities. Let me know what you think and if we should go forward with this approach.

madalingiurca avatar Apr 19 '24 06:04 madalingiurca

Thanks! I added a few comments and suggestions. :+1:

marcphilipp avatar Apr 19 '24 06:04 marcphilipp

@marcphilipp, I've wrapped up the changes and updated release notes + user guide (although not sure if former is needed). Let me know if anything else should be updated.

madalingiurca avatar Apr 22 '24 05:04 madalingiurca