An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

# Arbitrater

[![Download](https://maven-badges.herokuapp.com/maven-central/com.tyro.oss/arbitrater/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.tyro.oss/arbitrater)
[![Build Status](https://travis-ci.org/tyro/arbitrater.svg?branch=master)](https://travis-ci.org/tyro/arbitrater)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](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*