Testing oriented random value generators.
Usage
The library can be used in two usage scenarios.
Random values generation for testing purposes
To use random value generation in project tests add the dependency in test scope to the project.
<project ...>
...
<dependency>
<groupId>dev.orne.test</groupId>
<artifactId>generators</artifactId>
<version>0.2.0</version>
<scope>test</scope>
</dependency>
...
</project>
Warning: The library uses pseudorandom number generators (PRNGs) and must not be used for security-sensitive tasks.
The most basic usage requires only passing the value type to the
Generators.randomValue()
method:
Year year = Generators.randomValue(Year.class);
assertNotNull(year);
Alternatively, @Random
annotation can be used in JUnit 5 tests' fields and
parameters using the
supported validation annotations
as generation parameters:
@Test
void testSomething(@NotNull @Random Year year) {
assertNotNull(year);
}
For more advanced use cases see the ‘Test values generation’ article.
Provide new generator implementations
To provide support for new random value types generation add the dependency as optional to the project.
<project ...>
...
<dependency>
<groupId>dev.orne.test</groupId>
<artifactId>generators</artifactId>
<version>0.2.0</version>
<optional>true</optional>
</dependency>
...
</project>
See the ‘Provide new generators’ article for implementation details.
Features
The library provides the following features:
- SPI generators discovery
- Annotation based generators ordering
- Generators
- Typed generators
- Parameterizable generators
- Generic classes generation support
- Java Validation 2.1 based parameters extractors
NotNull
extractorSize
extractorMin
extractorMax
extractor
- Parameterizable typed generators
- Targeted generators
- Property type generator
- Method argument type generator
- Method return type generator
- Constructor argument type generator
- Constructor based generator
- Factory method based generator
- Primitives and wrapper types generators
java.lang.Boolean
generatorjava.lang.Byte
generatorjava.lang.Short
generatorjava.lang.Integer
generatorjava.lang.Long
generatorjava.lang.Float
generatorjava.lang.Double
generatorjava.lang.Character
generator
- Common types generators
java.lang.CharSequence
generatorjava.lang.Number
generatorjava.lang.String
generatorjava.io.File
generatorjava.math.BigInteger
generatorjava.math.BigDecimal
generatorjava.nio.charset.Charset
generatorjava.nio.file.Path
generatorjava.util.Calendar
generatorjava.util.Currency
generatorjava.util.Date
generatorjava.util.Locale
generatorjava.util.TimeZone
generatorjava.util.URI
generatorjava.util.URL
generatorjava.util.UUID
generatorjava.time.Clock
generatorjava.time.Duration
generatorjava.time.Instant
generatorjava.time.LocalDate
generatorjava.time.LocalDateTime
generatorjava.time.LocalTime
generatorjava.time.MonthDay
generatorjava.time.OffsetDateTime
generatorjava.time.OffsetTime
generatorjava.time.Period
generatorjava.time.Year
generatorjava.time.YearMonth
generatorjava.time.ZonedDateTime
generatorjava.time.ZoneId
generatorjava.time.ZoneOffset
generatorjava.time.chrono.Chronology
generator
- Arrays and collections generators
java.lang.Array
generatorjava.util.Collection
generatorjava.util.List
generatorjava.util.Set
generatorjava.util.Map
generator
- General generators
- Enumerations generator
- Annotated constructor based bean generator
- Annotated method based bean generator
- JUnit 5 extension
- Annotation based test values generation