IntRangeSource

@SourceProvider(value = IntRangeDataProvider::class)
annotation class IntRangeSource(val min: Int, val max: Int, val increment: Int = 1, val ascending: Boolean = true)

Annotation to indicate that the annotated int parameter should be populated with an integer range from min to max with an increment step in the ascending direction.

Samples

/**
 * This will generate 300 tests with the values 1 to 300
 * The values will be in ascending order
 */
@GeneratedParametersTest
fun testIntRangeSource(@IntRangeSource(min = 1, max = 300) value: Int) {
    assertThat(value).isBetween(1, 300)
}

/**
 * This will generate 149 tests with the values 1 to 300 with an increment of 2
 * The values will be in ascending order
 */
@GeneratedParametersTest
fun testIntRangeSourceWithIncrement(@IntRangeSource(min = 1, max = 300, increment = 2) value: Int) {
    assertThat(value).all {
        isBetween(1, 300)
        isOdd()
    }
}

/**
 * This will generate 149 tests with the values 1 to 300 with an increment of 2
 * The values will be in ascending order
 */
@GeneratedParametersTest
fun testIntRangeSourceWithIncrementDescending(
    @IntRangeSource(
        min = 1,
        max = 300,
        increment = 2,
        ascending = false
    ) value: Int
) {
    assertThat(value).all {
        isBetween(1, 300)
        isOdd()
    }
}

Properties

Link copied to clipboard
val ascending: Boolean = true

Whether the values should be in ascending or descending order. Default value is true.

Link copied to clipboard
val increment: Int = 1

The increment between values. Default value is 1.

Link copied to clipboard
val max: Int

The maximum value (inclusive)

Link copied to clipboard
val min: Int

The minimum value (inclusive)