@EnumSource

The annotation @EnumSource allows to specify a parameterized test in which the argument source is a Java enumeration class. By default, each value of the enumeration will be used to feed the parameterized test, one at a time.

For example, in the following test class, the method testWithEnum is annotated with @ParameterizedTest in conjunction with @EnumSource. As we can see, the value of this annotation is TimeUnit.class, which is a standard Java annotation (package java.util.concurrent) used to represent time duration. The possible values defined in this enumeration are NANOSECONDS, MICROSECONDS, MILLISECONDS, SECONDS, MINUTES, HOURS, and DAYS:

package io.github.bonigarcia;import static org.junit.jupiter.api.Assertions.assertNotNull ...

Get Mastering Software Testing with JUnit 5 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.