Annotation Interface RandomRange


@Target({PARAMETER,METHOD,FIELD}) @Retention(RUNTIME) public @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
     }
 }
Since:
1.0
Author:
Erik C. Thauvin
See Also:
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    int
    The maximum value (inclusive) for the random number generation.
    int
    The minimum value (inclusive) for the random number generation.
  • Element Details

    • max

      int max
      The maximum value (inclusive) for the random number generation.
      Returns:
      the maximum value, defaults to 100
      Default:
      100
    • min

      int min
      The minimum value (inclusive) for the random number generation.
      Returns:
      the minimum value, defaults to 0
      Default:
      0