longevity

A Persistence Framework for Scala and NoSQL

View project on GitHub

generating test data

The longevity context provides a tool for producing test data:

val generator = longevityContext.testDataGenerator

You can construct test data with the generate method by supplying the type that you want to generate:

val user: User = generator.generate[User]

All members are filled in with random values. For example, a Boolean will be true about half the time, and false about half the time. Options are non-empty about half the time. Sets and Lists have between 0 and 4 elements. Strings are composed of 8 random alphanumeric characters. You can use the generator to generate persistent components, KeyVals, Options, Sets, Lists, and even basic types such as String. For instance:

val userId = generator.generate[UserId]
val bools = generator.generate[List[Boolean]]
val sampleString = generator.generate[String]
prev: in memory repositories
up: testing your domain model
next: enforcing constraints