Skip to content

Latest commit

 

History

History
85 lines (70 loc) · 4.43 KB

README.md

File metadata and controls

85 lines (70 loc) · 4.43 KB

random-params-resolver

Build CodeQL Dependabot Updates Quality Gate Status Bugs Code Smells codecov GitHub License GitHub Release javadoc

Junit 5 randomized parameter resolver

Features

A JUnit 5 ParameterResolver that generates random values for parameters annotated with Randomize.

Annotation to generate random values for parameters. The supported parameter types are:

  • RandomGenerator
  • Integer / int
  • Long / long
  • String
  • byte[]

Examples

import io.github.lyang.randomparamsresolver.RandomParametersExtension;
import io.github.lyang.randomparamsresolver.RandomParametersExtension.Randomize;
import java.util.random.RandomGenerator;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

@ExtendWith(RandomParametersExtension.class)
class RandomizedParameterTest {
  @Test
  void randomized_generator(@Randomize RandomGenerator generator) {
    // random generator with seed from System.nanoTime()
  }

  @Test
  void randomized_generator_with_seed(
      @Randomize(seed = 787681803879958L) RandomGenerator generator) {
    // random generator with fixed seed to reproduce failures
    // seed value from previous test runs are logged like this:
    // INFO: Using seed 787681803879958 for RandomizedParameterTest#randomized_generator#arg0
  }

  @Test
  void randomized_integer(@Randomize int value, @Randomize Integer anotherValue) {
    // value is a random integer
    // anotherValue is a random integer with a different value
  }

  @Test
  void randomized_long_with_range(@Randomize(longMin = 0, longMax = 100) long value) {
    // value is a random long within [0, 100)
  }

  @Test
  void randomized_string(@Randomize String value, @Randomize(length = 10) String anotherValue) {
    // value is a random string with default length 5
    // anotherValue is a random string with length 10
    // default characters are from Character.UnicodeBlock.BASIC_LATIN
  }

  @Test
  void randomized_emoji_string(@Randomize(unicodeBlocks = "EMOTICONS") String value) {
    // characters are from Character.UnicodeBlock.EMOTICONS
  }

  @Test
  void randomized_byte_array(@Randomize byte[] value, @Randomize(length = 10) byte[] anotherValue) {
    // value is a random byte array with default length 5
    // anotherValue is a random byte array with length 10
  }
}

License

Apache-2.0