Kotest Generators List
Introduces the full list of Kotlin generators.
This page lists all current Kotest generators. There are two types of generators: Arbitrary generators and Exhaustive generators.
Most generators are available on all platforms. Some are JVM-only or JS-only.
Generators for Arrow are also provided as a separate module.
| Generator | Description | JVM | JS | Native |
|---|---|---|---|---|
| Nulls | ||||
arb.orNull() |
Generates arbitrary values from an arb instance mixed with null values. For example, Arb.int().orNull() can generate 1, -1, null, 8, 17, and so on. An overloaded version controls how often null is generated. |
✓ | ✓ | ✓ |
arb.orNull(nullProbability) |
Generates arbitrary values from an arb instance mixed with null values using the configured probability. | ✓ | ✓ | ✓ |
| Booleans | ||||
Arb.boolean() |
Returns an Arb that generates Boolean values. |
✓ | ✓ | ✓ |
Arb.booleanArray(length, content) |
Returns an Arb that generates BoolArray, where length generates the array length and content generates the array contents. |
✓ | ✓ | ✓ |
Exhaustive.boolean() |
Alternates between true and false. | ✓ | ✓ | ✓ |
| Chars | ||||
Arb.char(range1, range2,...) |
Returns arbitrary characters generated from one or more specified ranges. Multiple ranges make it possible to fill specific non-contiguous character ranges. | ✓ | ✓ | ✓ |
Arb.char(List<CharRange>) |
Returns characters distributed across the full list of character ranges. For example, Arb.char(listOf('A'..'C', 'X'..'Z')) generates A, B, C, X, Y, and Z with equal probability. |
|||
Arb.charArray(length, content) |
Returns an Arb that generates CharArray, where length generates the array length and content generates the array contents. |
✓ | ✓ | ✓ |
| Constants | ||||
Arb.constant(t) |
Returns an Arb that always returns t. |
✓ | ✓ | ✓ |
| Bytes | ||||
Arb.byte(min, max) |
Returns an Arb that generates Byte values from min to max, inclusive. Edge cases are min, -1, 0, 1, and max, included only when they are in the provided range. |
✓ | ✓ | ✓ |
Arb.positiveByte(min, max) |
Returns an Arb that generates positive Byte values from min to max, inclusive. Edge cases are 1 and max, included only when they are in the provided range. |
✓ | ✓ | ✓ |
Arb.negativeByte(min, max) |
Returns an Arb that generates negative Byte values from min to max, inclusive. Edge cases are min and -1, included only when they are in the provided range. |
✓ | ✓ | ✓ |
Arb.byteArray(length, content) |
Returns an Arb that generates ByteArray, where length generates the array length and content generates the array contents. |
✓ | ✓ | ✓ |
Arb.uByte(min, max) |
Returns an Arb that generates UByte values from min to max, inclusive. Edge cases are min, 1, and max, included only when they are in the provided range. |
✓ | ✓ | ✓ |
Arb.uByteArray(length, content) |
Returns an Arb that generates UByteArray, where length generates the array length and content generates the array contents. |
✓ | ✓ | ✓ |
| Shorts | ||||
Arb.short(min, max) |
Returns an Arb that generates Short values from min to max, inclusive. Edge cases are min, -1, 0, 1, and max, included only when they are in the provided range. |
✓ | ✓ | ✓ |
Arb.positiveShort(min, max) |
Returns an Arb that generates positive Short values from min to max, inclusive. Edge cases are 1 and max, included only when they are in the provided range. |
✓ | ✓ | ✓ |
Arb.negativeShort(min, max) |
Returns an Arb that generates negative Short values from min to max, inclusive. Edge cases are min and -1, included only when they are in the provided range. |
✓ | ✓ | ✓ |
Arb.shortArray(length, content) |
Returns an Arb that generates ShortArray, where length generates the array length and content generates the array contents. |
✓ | ✓ | ✓ |
Arb.uShort(min, max) |
Returns an Arb that generates UShort values from min to max, inclusive. Edge cases are min, 1, and max, included only when they are in the provided range. |
✓ | ✓ | ✓ |
Arb.uShortArray(length, content) |
Returns an Arb that generates UShortArray, where length generates the array length and content generates the array contents. |
✓ | ✓ | ✓ |
| Ints | ||||
Arb.int(min, max) |
Returns an Arb that generates Int values from min to max, inclusive. Edge cases are min, -1, 0, 1, and max, included only when they are in the provided range. |
✓ | ✓ | ✓ |
Arb.positiveInt(min, max) |
Returns an Arb that generates positive Int values from min to max, inclusive. Edge cases are 1 and max, included only when they are in the provided range. |
✓ | ✓ | ✓ |
Arb.nonNegativeInt(min, max) |
Returns an Arb that generates non-negative Int values from min to max, inclusive. Edge cases are 0, 1, and max, included only when they are in the provided range. |
✓ | ✓ | ✓ |
Arb.negativeInt(min, max) |
Returns an Arb that generates negative Int values from min to max, inclusive. Edge cases are min and -1, included only when they are in the provided range. |
✓ | ✓ | ✓ |
Arb.nonPositiveInt(min, max) |
Returns an Arb that generates non-positive Int values from min to max, inclusive. Edge cases are min, -1, and 0, included only when they are in the provided range. |
✓ | ✓ | ✓ |
Arb.intArray(length, content) |
Returns an Arb that generates IntArray, where length generates the array length and content generates the array contents. |
✓ | ✓ | ✓ |
Arb.uInt(min, max) |
Returns an Arb that generates UInt values from min to max, inclusive. Edge cases are min, 1, and max, included only when they are in the provided range. |
✓ | ✓ | ✓ |
Arb.uIntArray(length, content) |
Returns an Arb that generates UIntArray, where length generates the array length and content generates the array contents. |
✓ | ✓ | ✓ |
Exhaustive.ints(range) |
Returns every integer in the given range. | ✓ | ✓ | ✓ |
Arb.multiple(k, max) |
Generates multiples of k up to the maximum value. The edge case is 0. |
✓ | ✓ | ✓ |
Arb.factor(k) |
Generates factors of k. |
✓ | ✓ | ✓ |
| Longs | ||||
Arb.long(min, max) |
Returns an Arb that generates Long values from min to max, inclusive. Edge cases are min, -1, 0, 1, and max, included only when they are in the provided range. |
✓ | ✓ | ✓ |
Arb.positiveLong(min, max) |
Returns an Arb that generates positive Long values from min to max, inclusive. Edge cases are 1 and max, included only when they are in the provided range. |
✓ | ✓ | ✓ |
Arb.negativeLong(min, max) |
Returns an Arb that generates negative Long values from min to max, inclusive. Edge cases are min and -1, included only when they are in the provided range. |
✓ | ✓ | ✓ |
Arb.longArray(length, content) |
Returns an Arb that generates LongArray, where length generates the array length and content generates the array contents. |
✓ | ✓ | ✓ |
Arb.uLong(min, max) |
Returns an Arb that generates ULong values from min to max, inclusive. Edge cases are min, 1, and max, included only when they are in the provided range. |
✓ | ✓ | ✓ |
Arb.uLongArray(length, content) |
Returns an Arb that generates ULongArray, where length generates the array length and content generates the array contents. |
✓ | ✓ | ✓ |
Exhaustive.longs(range) |
Returns every long in the given range. | ✓ | ✓ | ✓ |
| Floats | ||||
Arb.float(min, max) |
Returns an Arb that generates Float values from min to max, inclusive. Edge cases include Float.NEGATIVE_INFINITY, min, -1.0, -Float.MIN_VALUE, -0.0, 0.0, Float.MIN_VALUE, 1.0, max, Float.POSITIVE_INFINITY, and Float.NaN only when they are in the provided range. |
✓ | ✓ | ✓ |
Arb.positiveFloat(min, max) |
Returns an Arb that generates positive Float values from min to max, inclusive. Float.MIN_VALUE, 1.0, max, and Float.POSITIVE_INFINITY are included only when they are in the provided range. |
✓ | ✓ | ✓ |
Arb.negativeFloat(min, max) |
Returns an Arb that generates negative Float values from min to max, inclusive. Edge cases are Float.NEGATIVE_INFINITY, min, -1.0, and -Float.MIN_VALUE, included only when they are in the provided range. |
✓ | ✓ | ✓ |
Arb.numericFloat(min, max) |
Returns an Arb that generates numeric Float values from min to max, inclusive. Edge cases are min, -1.0, -Float.MIN_VALUE, -0.0, 0.0, Float.MIN_VALUE, 1.0, and max, included only when they are in the provided range. |
✓ | ✓ | ✓ |
Arb.floatArray(length, content) |
Returns an Arb that generates FloatArray, where length generates the array length and content generates the array contents. |
✓ | ✓ | ✓ |
| Doubles | ||||
Arb.double(min, max) |
Returns an Arb that generates Double values from min to max, inclusive. Edge cases include Double.NEGATIVE_INFINITY, min, -1.0, -Double.MIN_VALUE, -0.0, 0.0, Double.MIN_VALUE, 1.0, max, Double.POSITIVE_INFINITY, and Double.NaN only when they are in the provided range. |
✓ | ✓ | ✓ |
Arb.positiveDouble(min, max) |
Returns an Arb that generates positive Double values from min to max, inclusive. Double.MIN_VALUE, 1.0, max, and Double.POSITIVE_INFINITY are included only when they are in the provided range. |
✓ | ✓ | ✓ |
Arb.negativeDouble(min, max) |
Returns an Arb that generates negative Double values from min to max, inclusive. Edge cases are Double.NEGATIVE_INFINITY, min, -1.0, and -Double.MIN_VALUE, included only when they are in the provided range. |
✓ | ✓ | ✓ |
Arb.numericDouble(min, max) |
Returns an Arb that generates numeric Double values from min to max, inclusive. Edge cases are min, -1.0, -Double.MIN_VALUE, -0.0, 0.0, Double.MIN_VALUE, 1.0, and max, included only when they are in the provided range. |
✓ | ✓ | ✓ |
Arb.doubleArray(length, content) |
Returns an Arb that generates DoubleArray, where length generates the array length and content generates the array contents. |
✓ | ✓ | ✓ |
| Enums | ||||
Arb.enum<T>() |
Randomly selects constants from the given enum. | ✓ | ✓ | ✓ |
Exhaustive.enum<T>() |
Iterates all constants defined in the given enum. | ✓ | ✓ | ✓ |
| Regional | ||||
localeArb() |
Generates locales in Java format, such as en_US or ca_ES_VALENCIA. |
✓ | ✓ | ✓ |
Arb.timezoneCodeThree() |
Generates time zones in three-letter format such as BST or EST. It does not include every possible time zone and is used only for data sampling. | ✓ | ✓ | ✓ |
Arb.geoLocation() |
Generates a GeoLocation object using random latitude and longitude points uniformly distributed across the globe. |
✓ | ✓ | ✓ |
| Strings | ||||
Arb.string(range) |
Generates printable random strings with size randomly selected from the given range. If no range is specified, (0..100) is used. Edge cases include empty strings and Unicode strings. |
✓ | ✓ | ✓ |
Arb.stringPattern(pattern) |
Uses RgxGen to generate strings matching the given pattern. | ✓ | ||
Exhaustive.azstring(range) |
Returns every AZ string in the specified range. For example, if the range is 1..2, it includes a, b, c, …, yz, zz. | ✓ | ✓ | ✓ |
Arb.email(localPartGen, domainGen) |
Generates arbitrary email addresses whose local part and domain part are random strings generated by the specified generators. Defaults are provided for both. | ✓ | ✓ | ✓ |
Arb.emailLocalPart() |
Generates an arbitrary local email part. | ✓ | ✓ | ✓ |
Arb.uuid(type) |
Generates a random UUID of the specified type. | ✓ | ||
Arb.domain(tlds, labelArb) |
Generates arbitrary domains using a random TLD, defaulting to one of the top 120 TLDs, and a label generator that generates the domain parts. | ✓ | ✓ | ✓ |
| Builders | ||||
Arb.bind(arbA, arbB, fn) |
Takes values from each of the two given arbs and passes them to the provided function to generate a value. | ✓ | ✓ | ✓ |
Arb.bind(arbA, arbB, arbC, fn) |
Takes values from each of the three given arbs and passes them to the provided function to generate a value. | ✓ | ✓ | ✓ |
Arb.bind(arbA, ...., fn) |
Takes values from each given arb and passes them to the provided function to generate a value. | ✓ | ✓ | ✓ |
| Combinatorics | ||||
Arb.choice(arbs) |
Randomly selects one of the given arbs and uses it to generate the next element. | ✓ | ✓ | ✓ |
Arb.choose(pairs) |
Generates values based on weights. For example, Arb.choose(1 to 'A', 2 to 'B') generates ‘A’ 33% of the time and ‘B’ 66% of the time. |
✓ | ✓ | ✓ |
Arb.frequency(list) |
Alias for choose. | ✓ | ✓ | ✓ |
Arb.shuffle(list) |
Generates random permutations of a list. For example, Arb.shuffle(listOf(1,2,3)) can generate listOf(3,1,2), listOf(1,3,2), and so on. |
✓ | ✓ | ✓ |
Arb.subsequence(list) |
Generates random subsequences of the given list starting at index 0, including the empty list. For example, Arb.subsequence(listOf(1,2,3)) can generate listOf(1), listOf(1,2), and so on. |
✓ | ✓ | ✓ |
| Collections | ||||
Arb.element(collection) |
Randomly selects one element from the given collection. | ✓ | ✓ | ✓ |
Arb.element(vararg T) |
Randomly selects one element from the vararg arguments. | ✓ | ✓ | ✓ |
Arb.list(gen, range) |
Generates lists whose values are created by the specified element generator. Each list size is randomly determined from the specified range. | ✓ | ✓ | ✓ |
Arb.set(gen, range) |
Generates sets whose values are created by the specified element generator. Each set size is randomly determined from the specified range. The slippage argument specifies how many attempts are made to generate each element before failing when the underlying arb cannot produce enough unique values for the requested size. | ✓ | ✓ | ✓ |
Arb.set(gen, range, slippage) |
Generates sets whose values are created by the specified element generator. Each set size is randomly determined from the specified range. | ✓ | ✓ | ✓ |
Arb<T>.chunked(range) |
Generates lists where each list is filled with elements from this receiver. Each chunk size is randomly selected from the given range. | ✓ | ✓ | ✓ |
Arb<T>.chunked(minSize, maxSize) |
Generates lists where each list is filled with elements from this receiver. Each chunk size is randomly selected from the given range parameters. | ✓ | ✓ | ✓ |
Exhaustive.collection(list) |
Enumerates each element of the list one by one. | ✓ | ✓ | ✓ |
| Maps | ||||
Arb.map(Arb<Pair<K,V>>, minSize, maxSize) |
Generates random maps with sizes between minSize and maxSize, where each element is generated from the specified arbitrary pair generator. |
✓ | ✓ | ✓ |
Arb.map(Arb<K>, Arb<V>, minSize, maxSize) |
Generates random maps with sizes between minSize and maxSize, where each key is generated from the specified key arb and each value from the specified value arb. |
✓ | ✓ | ✓ |
| Tuples | ||||
Arb.pair(arb1, arb2) |
Generates a Pair instance by taking each value of the pair from the two provided Arbs. |
✓ | ✓ | ✓ |
Arb.triple(arb1, arb2, arb3) |
Generates a Triple instance by taking each value of the triple from the three provided Arbs. |
✓ | ✓ | ✓ |
| Dates | ||||
Arb.date(range) |
Generates arbitrary dates using years between the given range. | ✓ | ||
Arb.datetime(range) |
Generates arbitrary date-times using years between the given range. | ✓ | ||
Arb.localDateTime(range) |
Generates arbitrary LocalDateTime values using years between the given range. |
✓ | ||
Arb.localDate(range) |
Generates arbitrary LocalDate values using years between the given range. |
✓ | ||
| Durations | ||||
Arb.duration(range) |
Generates arbitrary durations from the specified range. | ✓ | ✓ | ✓ |
| Kotlinx Date/Time | Requires the io.kotest.extensions:kotest-property-datetime module. |
|||
Arb.date(yearRange) |
Randomly generates LocalDate values using years in the given range and other fields. |
✓ | ✓ | ✓ |
Arb.datetime(yearRange, hourRange, minuteRange, secondRange) |
Generates LocalDateTime values using all fields from the given ranges. |
✓ | ✓ | ✓ |
Arb.instant(range) |
Generates Instant values with epochs randomly generated from the given range. |
✓ | ✓ | ✓ |
| Networking | ||||
Arb.ipAddressV4() |
Generates arbitrary IP addresses in a.b.c.d format, where each part is between 0 and 255. | ✓ | ✓ | ✓ |