Skip to content

rweisleder/jfairy-junit-extension

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JUnit Extension for jFairy

Build Status Maven Central Javadoc

jFairy is a fake data generator. This JUnit extension provides simple injection of random data into fields and method parameters.

@Test
@ExtendWith(FairyExtension.class)
void withRandomPerson(@Random Person person) {
  System.out.println(person.getFullName());
  // Chloe Barker
}

Documentation

Setup

This extension resolves fields and method parameters annotated with @Random.

@ExtendWith(FairyExtension.class)
class MyTest {
  
  @Random
  private Person person1;

  @Test
  void example(@Random Person person2) {
    // ...
  }
}

The random generator can be customized with a locale and a seed.

@Random(locale = "de", seed = 1234)

Supported Object Types

  • boolean and Boolean

    @Random
    private boolean trueOrFalse;
  • int and Integer which can be customized using @IntegerWith

    @Random
    @IntegerWith(min = 50, max = 100)
    private int i;
  • String which can be customized using @StringWith

    @Random
    @StringWith(maxLength = 20)
    private String randomString;
    
    @Random(locale = "de")
    @StringWith(type = WORD)
    private String germanWord;
  • Enum types

    @Random
    private Month month;
  • Person which can be customized using @PersonWith

    @Random
    @PersonWith(sex = MALE, minAge = 13, maxAge = 19)
    private Person maleTeenager;

Samples

Look into the ExampleTests.

About

Extension for JUnit which provides injection of random data

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages