Coder Social home page Coder Social logo

randolf's Introduction

Randolf the reindeer

Autogenerated data for your tests.

Download CircleCI

This is how it looks in action:

enum class BeanType { ROBUSTA, ARABICA }
data class Group(val name: String)
data class User(
    val firstName: String,
    val name: String,
    val age: Int,
    val lat: Double,
    val lon: Double,
    val isBoss: Boolean,
    val teamSize: Short,
    val flags: Byte,
    val shortName: Char,
    val efficiency: Float,
    val favoriteCoffee: BeanType,
    val groups: List<Group>
)
print(Randolf().create<User>())
        
//=> User(firstName=QV muCLbUVfVheboeSuN, name=MSdOzpRCFIykprACOHjv, age=2116525025, lat=0.9518687079417872, lon=0.8331958938906572, isBoss=false, teamSize=4310, flags=83, shortName=Z, efficiency=0.76879007, favoriteCoffee=ARABICA, groups=[Group(name=TpiFXUrucFA cMARKLiR), Group(name=floFeNep XBEZUfXwQgL)])

Usage:

Add this to your Gradle dependencies:

    testCompile("com.christophsturm:randolf:0.1.0")

Add JCenter if you haven't already:

repositories {
    jcenter()
}

You can create any Kotlin data class like in the example above. All fields will be set to random values, even nullable fields. You can chose to set only necessary fields by calling Randolf.create(RandolfConfig(minimal=true)) instead. This will set all nullable fields to null, numbers to 0 and make strings, lists and maps empty. For more usage examples take a look at the unit tests.

Currently supported types:

  • String
  • Int
  • Long
  • Double
  • Short
  • Float
  • Byte
  • Boolean
  • Char
  • Enums
  • List
  • Set
  • Collection
  • Map

Configuration

If you want to change defaults or support more types, you can pass a RandolfConfig to the Randolf constructor.

Here is a config that returns now for Instant:

RandolfConfig(additionalValueCreators = mapOf(Instant::class to { _, _ -> Instant.now() }))

You can override supported types, and use the name and type of the field:

RandolfConfig(additionalValueCreators = mapOf(String::class to { type: KType, name: String ->
                    "field $name of type $type"
                }))

You can also inject a random generator for example to set the seed:

RandolfConfig(random = Random(1234))

Next steps:

  • add an optional non random mode inspired by Fakir
  • build for Kotlin/JS and Kotlin/Native.

Download CircleCI

randolf's People

Contributors

christophsturm avatar bitkid avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.