Proposal for generation of test data. #154
nwokafor-choongsaeng
started this conversation in
Proposal
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Proposal for generation of test data.
Introduction
During testing we often need to feed the system with some data. In some cases such as volume testing or property-based testing we don't care about the specific values only that they are valid. There are many tools out there to generate arbitrary data and they all rely on some kind of description of the shape of the data and potential constraints. Some do this with description languages, others use combinator libraries that allow you to compose generators (property-based testing frameworks tend to do this).
The Morphir IR already contains all the necessary information so we could automate this and as a Morphir user you could get this for free.
User Stories
How it works
Without getting too much into the implementation details, this feature provides pseudo-random data generation using a seed. It is implemented as building blocks that can be composed further to generate very complex data.
example
using the API above, we can create a create a Generator for a User type that we define
This makes it easy to build new types of generators for Morphir and even generators as powerful as a Morphir model generator.
Seeds
Sometimes it is useful to be able to reproduce the sequences given by a pseudo-random number generator. By re-using a seed value, the same sequence should be reproducible from run to run, and in fact, it is a requirement in functional programming that function outputs are predictable.
Seeds are how we ensure reproducible randomness. Our generator takes an initial value (seed) and applies an algorithm to generate seemingly random values, which means that providing the same seed multiple times will produce the same
sequence of randomness over and over again. This is useful when we want to reproduce testing a function with some input that causes our logic to fail.
What can data be generated for?
Data can be generated for any type that is serializable. Which excludes
Function
type.How to generate data?
An initial integration of this feature will be as a cli feature.
Data can be generated into a json file by running a command:
Beta Was this translation helpful? Give feedback.
All reactions