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
}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)-
booleanandBoolean@Random private boolean trueOrFalse;
-
intandIntegerwhich can be customized using@IntegerWith@Random @IntegerWith(min = 50, max = 100) private int i;
-
Stringwhich 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;
-
Personwhich can be customized using@PersonWith@Random @PersonWith(sex = MALE, minAge = 13, maxAge = 19) private Person maleTeenager;
Look into the ExampleTests.