Skip to main content
Version: 5.9

Generators List

This page lists all current generators in Kotest. There are two types of generator: arbitrary and exhaustive.

Most generators are available on all platforms. Some are JVM or JS specific.

We also provide generators for Arrow as a separate module.

GeneratorDescriptionJVMJSNative
Nulls
arb.orNull()Generates random values from the arb instance, with null values mixed in. For example, Arb.int().orNull() could generate 1, -1, null, 8, 17, and so on. Has overloaded versions to control the frequency of nulls being generated.✓✓✓
arb.orNull(nullProbability)Generates random values from the arb instance, with null values mixed in using the defined probability.✓✓✓
Booleans
Arb.boolean()Returns an Arb that produces Booleans.✓✓✓
Arb.booleanArray(length, content)Returns an Arb that produces BoolArrays where length produces the length of the arrays and content produces the content of the arrays.✓✓✓
Exhaustive.boolean()Alternatives between true and false.✓✓✓
Chars
Arb.char(range1, range2,...)Returns random char's generated from one or more given ranges. By supporting multiple ranges, it is possible to specific non-consecutive ranges of characters to populate values from.✓✓✓
Arb.char(List<CharRange>)Returns chars distributed across the lists of chars. For example, Arb.char(listOf('A'..'C', 'X'..'Z')) will generate values of A, B, C, X, Y, Z with equal probability.
Arb.charArray(length, content)Returns an Arb that produces CharArrays where length produces the length of the arrays and content produces the content of the arrays.✓✓✓
Constants
Arb.constant(t)Returns an Arb that always returns t✓✓✓
Bytes
Arb.byte(min, max)Returns an Arb that produces Bytes from min to max (inclusive). The edge cases are min, -1, 0, 1 and max which are only included if they are in the provided range.✓✓✓
Arb.positiveByte(min, max)Returns an Arb that produces positive Bytes from min to max (inclusive). The edge cases are 1 and max which are only included if they are in the provided range.✓✓✓
Arb.negativeByte(min, max)Returns an Arb that produces negative Bytes from min to max (inclusive). The edge cases are min and -1 which are only included if they are in the provided range.✓✓✓
Arb.byteArray(length, content)Returns an Arb that produces ByteArrays where length produces the length of the arrays and content produces the content of the arrays.✓✓✓
Arb.uByte(min, max)Returns an Arb that produces UBytes from min to max (inclusive). The edge cases are min, 1 and max which are only included if they are in the provided range.✓✓✓
Arb.uByteArray(length, content)Returns an Arb that produces UByteArrays where length produces the length of the arrays and content produces the content of the arrays.✓✓✓
Shorts
Arb.short(min, max)Returns an Arb that produces Shorts from min to max (inclusive). The edge cases are min, -1, 0, 1 and max which are only included if they are in the provided range.✓✓✓
Arb.positiveShort(min, max)Returns an Arb that produces positive Shorts from min to max (inclusive). The edge cases are 1 and max which are only included if they are in the provided range.✓✓✓
Arb.negativeShort(min, max)Returns an Arb that produces negative Shorts from min to max (inclusive). The edge cases are min and -1 which are only included if they are in the provided range.✓✓✓
Arb.shortArray(length, content)Returns an Arb that produces ShortArrays where length produces the length of the arrays and content produces the content of the arrays.✓✓✓
Arb.uShort(min, max)Returns an Arb that produces UShorts from min to max (inclusive). The edge cases are min, 1 and max which are only included if they are in the provided range.✓✓✓
Arb.uShortArray(length, content)Returns an Arb that produces UShortArrays where length produces the length of the arrays and content produces the content of the arrays.✓✓✓
Ints
Arb.int(min, max)Returns an Arb that produces Ints from min to max (inclusive). The edge cases are min, -1, 0, 1 and max which are only included if they are in the provided range.✓✓✓
Arb.positiveInt(min, max)Returns an Arb that produces positive Ints from min to max (inclusive). The edge cases are 1 and max which are only included if they are in the provided range.✓✓✓
Arb.nonNegativeInt(min, max)Returns an Arb that produces non negative Ints from min to max (inclusive). The edge cases are 0, 1 and max which are only included if they are in the provided range.✓✓✓
Arb.negativeInt(min, max)Returns an Arb that produces negative Ints from min to max (inclusive). The edge cases are min and -1 which are only included if they are in the provided range.✓✓✓
Arb.nonPositiveInt(min, max)Returns an Arb that produces non positive Ints from min to max (inclusive). The edge cases are min, -1 and 0 which are only included if they are in the provided range.✓✓✓
Arb.intArray(length, content)Returns an Arb that produces IntArrays where length produces the length of the arrays and content produces the content of the arrays.✓✓✓
Arb.uInt(min, max)Returns an Arb that produces UInts from min to max (inclusive). The edge cases are min, 1 and max which are only included if they are in the provided range.✓✓✓
Arb.uIntArray(length, content)Returns an Arb that produces UIntArrays where length produces the length of the arrays and content produces the content of the arrays.✓✓✓
Exhaustive.ints(range)Returns all ints in the given range.✓✓✓
Arb.multiple(k, max)Generates multiples of k up a max value. The edge cases are 0.✓✓✓
Arb.factor(k)Generates factors of k.✓✓✓
Longs
Arb.long(min, max)Returns an Arb that produces Longs from min to max (inclusive). The edge cases are min, -1, 0, 1 and max which are only included if they are in the provided range.✓✓✓
Arb.positiveLong(min, max)Returns an Arb that produces positive Longs from min to max (inclusive). The edge cases are 1 and max which are only included if they are in the provided range.✓✓✓
Arb.negativeLong(min, max)Returns an Arb that produces negative Longs from min to max (inclusive). The edge cases are min and -1 which are only included if they are in the provided range.✓✓✓
Arb.longArray(length, content)Returns an Arb that produces LongArrays where length produces the length of the arrays and content produces the content of the arrays.✓✓✓
Arb.uLong(min, max)Returns an Arb that produces ULongs from min to max (inclusive). The edge cases are min, 1 and max which are only included if they are in the provided range.✓✓✓
Arb.uLongArray(length, content)Returns an Arb that produces ULongArrays where length produces the length of the arrays and content produces the content of the arrays.✓✓✓
Exhaustive.longs(range)Returns all longs in the given range.✓✓✓
Floats
Arb.float(min, max)Returns an Arb that produces Floats from min to max (inclusive). The edge cases are 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 which are only included if they are in the provided range.✓✓✓
Arb.positiveFloat(min, max)Returns an Arb that produces positive Floats from min to max (inclusive). Float.MIN_VALUE, 1.0, max, Float.POSITIVE_INFINITY which are only included if they are in the provided range.✓✓✓
Arb.negativeFloat(min, max)Returns an Arb that produces negative Floats from min to max (inclusive). The edge cases are Float.NEGATIVE_INFINITY, min, -1.0 and -Float.MIN_VALUE which are only included if they are in the provided range.✓✓✓
Arb.numericFloat(min, max)Returns an Arb that produces numeric Floats from min to max (inclusive). The edge cases are min, -1.0, -Float.MIN_VALUE, -0.0, 0.0, Float.MIN_VALUE, 1.0 and max which are only included if they are in the provided range.✓✓✓
Arb.floatArray(length, content)Returns an Arb that produces FloatArrays where length produces the length of the arrays and content produces the content of the arrays.✓✓✓
Doubles
Arb.double(min, max)Returns an Arb that produces Doubles from min to max (inclusive). The edge cases are 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 which are only included if they are in the provided range.✓✓✓
Arb.positiveDouble(min, max)Returns an Arb that produces positive Doubles from min to max (inclusive). Double.MIN_VALUE, 1.0, max, Double.POSITIVE_INFINITY which are only included if they are in the provided range.✓✓✓
Arb.negativeDouble(min, max)Returns an Arb that produces negative Doubles from min to max (inclusive). The edge cases are Double.NEGATIVE_INFINITY, min, -1.0 and -Double.MIN_VALUE which are only included if they are in the provided range.✓✓✓
Arb.numericDouble(min, max)Returns an Arb that produces numeric Doubles from min to max (inclusive). The edge cases are min, -1.0, -Double.MIN_VALUE, -0.0, 0.0, Double.MIN_VALUE, 1.0 and max which are only included if they are in the provided range.✓✓✓
Arb.doubleArray(length, content)Returns an Arb that produces DoubleArrays where length produces the length of the arrays and content produces the content of the arrays.✓✓✓
Enums
Arb.enum<T>()Randomly selects constants from the given enum.✓✓✓
Exhaustive.enum<T>()Iterates all the constants defined in the given enum.✓✓✓
Regional
Arb.locale()Generates locales in the Java format, eg en_US or ca_ES_VALENCIA.✓✓✓
Arb.timezoneCodeThree()Generates timezones in the format ABC, for example BST or EST. Does not include all possible timezones, and is only used for sampling data.✓✓✓
Arb.geoLocation()Generates GeoLocation objects with random latitude/longitude points uniformly distributed on the globe.✓✓✓
Strings
Arb.string(range)Generates random printable strings with a randomly chosen size from the given range. If range is not specified then (0..100) is used. The edge cases include empty string, a blank string and a unicode string.✓✓✓
Arb.stringPattern(pattern)Generates strings that match given pattern using RgxGen✓
Exhaustive.azstring(range)Returns all A-Z strings in the given range. For example if range was 1..2 then a, b, c, ...., yz, zz would be included.✓✓✓
Arb.email(localPartGen, domainGen)Generates random emails where the local part and domain part are random strings generated by the given generators. A default value is provided for both.✓✓✓
Arb.emailLocalPart()Generates random local email parts✓✓✓
Arb.uuid(type)Generates random UUIDs of the given type✓
Arb.domain(tlds, labelArb)Generates random domains with a random tld (defaults to any of the top 120 TLDs) and a label generator, which generates domain parts.✓✓✓
Builders
Arb.bind(arbA, arbB, fn)Generates values by pulling a value from each of the two given arbs and then passing those values to the supplied function.✓✓✓
Arb.bind(arbA, arbB, arbC, fn)Generates values by pulling a value from each of the three given arbs and then passing those values to the supplied function.✓✓✓
Arb.bind(arbA, ...., fn)Generates values by pulling a value from each of the given arbs and then passing those values to the supplied function.✓✓✓
Combinatorics
Arb.choice(arbs)Randomly selects one of the given arbs and then uses that to generate the next element.✓✓✓
Arb.choose(pairs)Generates values based on weights. For example, Arb.choose(1 to 'A', 2 to 'B') will generate 'A' 33% of the time and 'B' 66% of the time.✓✓✓
Arb.frequency(list)Alias to choose✓✓✓
Arb.shuffle(list)Generates random permutations of a list. For example, Arb.shuffle(listOf(1,2,3)) could generate listOf(3,1,2), listOf(1,3,2) and so on.✓✓✓
Arb.subsequence(list)Generates a random subsequence of the given list starting at index 0 and including the empty list. For example, Arb.subsequence(listOf(1,2,3)) could generate listOf(1), listOf(1,2), and so on.✓✓✓
Collections
Arb.element(collection)Randomly selects one of the elements of the given collection.✓✓✓
Arb.element(vararg T)Randomly selects one of the elements from the varargs.✓✓✓
Arb.list(gen, range)Generates lists where values are generated by the given element generator. The size of each list is determined randomly by the specified range.✓✓✓
Arb.set(gen, range)Generates sets where values are generated by the given element generator. The size of each set is determined randomly by the specified range. The slippage argument specifies how many attempts will be made to generate each element before erroring, in the case that the underlying arb does not have enough unique values to satisfy the set size.✓✓✓
Arb.set(gen, range, slippage)Generates sets where values are generated by the given element generator. The size of each set is determined randomly by the specified range.✓✓✓
Arb<T>.chunked(range)Generates lists where each list is populated from elements of this receiver. The size of each size is randomly chosen within the given range.✓✓✓
Arb<T>.chunked(minSize, maxSize)Generates lists where each list is populated from elements of this receiver. The size of each size is randomly chosen within 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, each one with a size between minSize and maxSize, and each element generated from the given Pair arb.✓✓✓
Arb.map(Arb<K>, Arb<V>, minSize, maxSize)Generates random maps, each one with a size between minSize and maxSize, and each key generated from the given key arb and each value generated from the given value arb.✓✓✓
Tuples
Arb.pair(arb1, arb2)Generates Pair instances where each value of the pair is drawn from the two provided arbs✓✓✓
Arb.triple(arb1, arb2, arb3)Generates Triple instances where each value of the triple is drawn from the three provided arbs✓✓✓
Dates
Arb.date(ranges)Generates random dates with the year between the given range✓
Arb.datetime(ranges)Generates random date times with the year between the given range✓
Arb.localDateTime(ranges)Generates random LocalDateTime's with the year between the given range✓
Arb.localDate(ranges)Generates random LocalDate's with the year between the given range✓
Durations
Arb.duration(ranges)Generates random durations in the given range.✓✓✓
Kotlinx DateTimeRequires io.kotest.extensions:kotest-property-datetime module
Arb.date(yearRange)Generates LocalDates with the year between the given range and other fields randomly.✓✓✓
Arb.datetime(yearRange, hourRange, minuteRange, secondRage)Generates LocalDateTimes with all fields in the given ranges✓✓✓
Arb.instant(range)Generates Instants with the epoch randomly generated in the given range✓✓✓
Networking
Arb.ipAddressV4()Generates random IP addresses in the format a.b.c.d, where each part is between 0 and 255.✓✓✓