Package rife.bld.extension.testing
Annotation Interface RandomRange
JUnit annotation for generating random integer values within a specified range.
This annotation can be applied to test method parameters of type int to automatically
inject random values during test execution. It can also be applied at the method level to
configure default settings for all int parameters in that method.
Example usage:
@ExtendWith(RandomRangeResolver.class)
public class MyTest {
// Parameter-level annotation
@Test
public void testMethod(@RandomRange(min = 1, max = 10) int randomValue) {
// randomValue will be a random integer between 1 and 10 (inclusive)
}
// Method-level annotation for single parameter
@Test
@RandomRange(min = 5, max = 15)
public void testWithMethodLevel(int randomValue) {
// randomValue will be a random integer between 5 and 15 (inclusive)
}
// Method-level annotation applies to all int parameters
@Test
@RandomRange(min = 1, max = 100)
public void testMultiple(int first, int second) {
// Both first and second will be random integers between 1 and 100 (inclusive)
}
// Parameter-level annotation overrides method-level
@Test
@RandomRange(min = 1, max = 10)
public void testMixed(int defaultRange, @RandomRange(min = 50, max = 60) int customRange) {
// defaultRange: 1-10, customRange: 50-60
}
// Field injection
@RandomRange(min = 1, max = 100)
private int myRandomInt;
@Test
void test() {
// myRandomInt is initialized before test
}
// List of random integers
@Test
void test(@RandomRange(size = 5, min = 1, max = 10) List<Integer> randomList) { ... }
// Set of random integers
@Test
void test(@RandomRange(size = 10, min = 0, max = 100) Set<Integer> randomSet) { ... }
// Field injection for List
@RandomRange(size = 5, min = 1, max = 50)
private List<Integer> randomInts;
// Field injection for Set
@RandomRange(size = 10, min = 10, max = 20)
private Set<Integer> randomIntSet;
}- Since:
- 1.0
- Author:
- Erik C. Thauvin
- See Also:
-
Optional Element Summary
Optional Elements
-
Element Details
-
max
int maxThe maximum value (inclusive) for the random number generation.- Returns:
- the maximum value, defaults to 100
- Default:
- 100
-
min
int minThe minimum value (inclusive) for the random number generation.- Returns:
- the minimum value, defaults to 0
- Default:
- 0
-
size
int sizeThe number of random integers to generate for List or Set parameters.When
sizeis greater than 0, this annotation can be applied to:List<Integer>parameters - generates a list of random integersSet<Integer>parameters - generates a set of unique random integers
When
sizeis 0 (default), this annotation applies to singleintparameters.- Returns:
- the number of integers to generate, or 0 for single integer generation
- Throws:
IllegalArgumentException- if size is negative during resolution
- Default:
- 0
-