O'Reilly logo

Mastering Software Testing with JUnit 5 by Boni García

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required