https://github.com/tyro/arbitrater
Arbitrater is a Kotlin library for creating arbitrary instances of classes by reflection for use in testing. In contrast to POJO generators, it supports Kotlin's optional parameters and nullable types.
https://github.com/tyro/arbitrater
kotlin-testing random-generation testing
Last synced: 4 months ago
JSON representation
Arbitrater is a Kotlin library for creating arbitrary instances of classes by reflection for use in testing. In contrast to POJO generators, it supports Kotlin's optional parameters and nullable types.
- Host: GitHub
- URL: https://github.com/tyro/arbitrater
- Owner: tyro
- License: apache-2.0
- Archived: true
- Created: 2018-01-09T02:07:08.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-02-11T04:04:22.000Z (over 4 years ago)
- Last Synced: 2024-04-16T07:05:59.629Z (about 2 years ago)
- Topics: kotlin-testing, random-generation, testing
- Language: Kotlin
- Homepage:
- Size: 111 KB
- Stars: 41
- Watchers: 9
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Arbitrater
[](https://maven-badges.herokuapp.com/maven-central/com.tyro.oss/arbitrater)
[](https://travis-ci.org/tyro/arbitrater)
[](http://www.apache.org/licenses/LICENSE-2.0)
Arbitrater is a library for creating arbitrary instances of classes by reflection,
for example to use in testing. It was designed primarily for use with Kotlin 'data classes',
but may work with regular classes too.
It is similar to libraries like [random-beans](https://github.com/benas/random-beans) and
[podam](https://devopsfolks.github.io/podam/), but with support for nullable types and default values.
## Quick start
```kotlin
data class Order(val name: String, val quantity: Int = 1, val promotionCode: String?)
val defaultOrder: Order = arbitrary()
println(defaultOrder) // Order(description=\VccV/esz{54[!FAU(a{, quantity=1, promotionCode=5b$`i1AsT54t[Hwf%W*&)
val customOrder = Order::class.arbitrater()
.generateNulls()
.useDefaultValues(false)
.createInstance()
println(customOrder) // Order(description= 5{L_vUnvMIJ!y]03*