junit-team / junit5

✅ The 5th major version of the programmer-friendly testing framework for Java and the JVM

Home Page:https://junit.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

bjmi opened this issue · 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.)

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

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

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

Hi @madalingiurca,

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

So feel free to submit a PR!

@madalingiurca Have you already started on this?

@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

No worries! Please let us know when you start.

@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.

Thanks! I added a few comments and suggestions. 👍

@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.