LocalTimeSource
Annotation to be utilized on a parameter of type LocalTime in a parametrized test. The annotated parameter's value will be populated with a randomized value derived from the provided values array.
The values array should consist of time string values, formatted according to the timeFormat property.
Default value for timeFormat is "HH:mm".
Samples
/**
* This will generate 5 tests with the values "2020-01-01", "2021-01-01", "2022-01-01", "2023-01-01", "2024-01-01"
*/
@GeneratedParametersTest
fun testLocalTimeSource(
@LocalTimeSource(
values = [
"00:00",
"02:00",
"04:00",
"06:00",
"08:00"
]
)
value: LocalTime
) {
assertThat(value).isLessThan(LocalTime.parse("09:00"))
}
/**
* This will generate 5 tests with the values "01/01/2020", "01/01/2021", "01/01/2022", "01/01/2023", "01/01/2024"
* The values will be parsed using the format "MM/dd/yyyy"
*/
@GeneratedParametersTest
fun testLocalTimeSourceWithFormat(
@LocalTimeSource(
values = [
"00:00:01",
"02:00:02",
"03:00:03",
"04:00:04",
"05:00:05"
],
timeFormat = "hh:mm:ss"
)
value: LocalTime
) {
assertThat(value).isLessThan(LocalTime.parse("06:00"))
}Content copied to clipboard
Properties
Link copied to clipboard
A String representing the pattern to be used for parsing the values into LocalTime instances. Default value is "HH:mm".
Link copied to clipboard
An array of string representing time, to be converted into LocalTime instances. The time strings should be formatted according to the timeFormat property.