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

Implicit conversion

Internally, JUnit 5 handles a set of rules for the conversion of parameters from String to the actual argument type. For example, if @ParameterizedTests declares a parameter of type TimeUnit, but the declared source is a String, internally this String will be converted to TimeUnit. The following table summarizes the rules of implicit conversions in JUnit 5 for parameterized test arguments:

Target Type

Example

boolean/Boolean

"false" -> false

byte/Byte

"1" -> (byte) 1

char/Character

"a" -> 'a'

short/Short

"2" -> (short) 2

int/Integer

"3" -> 3

long/Long

"4" -> 4L

float/Float

"5.0" -> 5.0f

double/Double

"6.0" -> 6.0d

Enum subclass

"SECONDS" -> TimeUnit.SECONDS

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