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

Explicit conversion

If the implicit conversion provided by JUnit 5 is not enough to cover our needs, we can use the explicit conversion capability. Thanks to this feature, we can specify a class which is going to make the custom conversion of parameter types. This custom converter is identified with the annotation @ConvertWith, referring to the argument to be converted with. Consider the following example. This parameterized test declares a custom converter for its test method argument:

package io.github.bonigarcia;import static org.junit.jupiter.api.Assertions.assertNotNull;import java.util.concurrent.TimeUnit;import org.junit.jupiter.params.ParameterizedTest;import org.junit.jupiter.params.converter.ConvertWith;import org.junit.jupiter.params.provider.EnumSource; ...

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