kotlinunit-testingtestingdata-generation

Generation of random data for tests


In Java, I can do things with EasyRandom

final EasyRandom generator = new EasyRandom();
final MyDto dummy = generator.nextObject(MyDto.class);
// test

But I haven't found a suitable way to do something like this in Kotlin

Which libraries should be used to create fake test data?


Solution

  • I like KotlinFixture.

    You can do things like this with it

    val randomElement = fixture(listOf(<your objects>))
    

    and other fake data generation.

    https://github.com/appmattus/kotlinfixture