Skip to content

Data Generation

Building on the foundation of creating and using variables, Jikken also supports generating data using the same variable structure. Generated values are treated just like normal variables, so they can be embedded and reused the same way in your test definitions. These values can be completely random or you can specify constraints to generate data based on your own validity criteria.

Generating a value

Let’s take a look at a few examples of generating data of different types.

Numbers

In the simplest case, we just want to generate a single random value, such as a number.

Let’s start with an unbounded random integer:

variables:
- name: number
type: Integer

For this case, all we need to do is a create a variable, give it a name, and specify type: Integer. Since no value is specified, it will be given a random value based on the type - in this case, an integer.

What if we want a positive integer, or an integer in a specific range?

variables:
- name: number
type: Integer
min: 0
max: 100

If we specify a min or max, the generated value will be bounded by those values. In this case, we will get a random number between 0 and 100. We could also set min: 0 without a max to get a positive integer.

Decimal values can be generated in the same way using type: Float.

Strings

Let’s look at how we might generate a string value in the same way:

variables:
- name: text
type: String

Just as before, if we only specify type: String with no other constraints, a random string value will be generated.

And as we might expect, we can also add some constraints to create a more specific random string:

variables:
- name: text
type: String
minLength: 5
maxLength: 10

By specifying minLength and maxLength, we can generate a string with a length of between 5 and 10 characters. You can also use length to specify an exact length.

What if our API accepts a pre-defined set of values, such as an enum?

variables:
- name: enum
type: String
anyOf: ["value1", "value2"]

We can use the anyOf constraint to specify a set of allowed values, and the variable will contain a randomly chosen value from that set.

In addition to general strings, there are also two special string types - Name and Email. When used, these will generate a random appropriate value for the given type - a full name or an email address, respectively.

Lists

Jikken also supports generating more complex types, like list and object.

Let’s look at a list first:

variables:
- name: list
type: List
length: 5

Here, we have specified type: List with a length of 5. By default, this will generate a list of 5 integers. Just like with strings, we can also specify a minLength and maxLength for a variable-length list.

What if we don’t want integers, but strings instead?

variables:
- name: listOfStrings
type: List
length: 5
schema:
type: String

For complex types, the schema block is where we define the type and constraints for the inner or nested values. In this case, all we’re specifying is that the items in the list should be of type: String. This will generate a list of 5 random string values.

variables:
- name: listOfStrings
type: List
length: 5
schema:
type: String
length: 10

Going a step further, we can also define constraints inside the schema block, and these will apply to the items inside the list. In this case, we’re specifying length: 10 for each string, so this will produce a list of 5 random strings, each of which is 10 characters long.

We can use any of the constraints applicable to a string here (or, of course, any other type instead).

Objects

As you might expect, objects are a bit different. There is no default value for a random object, and none of the constraints we’ve talked about directly apply.

variables:
- name: object
type: Object
schema:
"field1": "value"
"field2":
type: String
length: 10

Objects are generated entirely from the schema block. Each desired field is defined as a member of schema, and these can be literal values, generated values, or a mixture of the two.

In the example above, the object generated has a “field1” with a value of “value” (a literal value), and a “field2” with a random 10-character string (a generated value).

variables:
- name: objectWithList
type: Object
schema:
"field1": "value"
"field2":
type: List
length: 5
schema:
type: String
length: 10

We can also nest a complex type inside of the object. Here, we’ve changed “field2” to a list of strings, so it will now contain a list of 5 random 10-character strings instead of a single value.

What about another object?

variables:
- name: nestedObject
type: Object
schema:
"field1": "value"
"field2":
type: Object
schema:
"field3":
type: Integer
min: 0
max: 100

Of course, we can nest an object inside the field of another object. Here, “field2” now contains a nested object, which has a “field3” with a random integer between 0 and 100.

Lastly, let’s revisit lists for just a moment:

variables:
- name: listOfObjects
type: List
length: 5
schema:
type: Object
schema:
"field1": "value"
"field2":
type: String
length: 10

We can also create a list of objects by using a variable of type: List with a schema of type: Object. This will generate a list of 5 random objects, each one with a “field1” with the literal “value” and a “field2” with a random 10-character string.

As you can imagine, these different types can be nested and combined to generate whatever specific data structure you might need, while still allowing the flexibility of using random values only where needed.

For more information on variables and how to use them, see the Variables page.

Type reference

This section contains examples with all valid fields for each supported data type, for easy reference.

For details and descriptions of each field, see the Full Format page.

Boolean

Generates a boolean value. The alias Bool is also supported.

variables:
- name: bool
type: Boolean

Example value:

false

Integer

Generates a 64-bit integer value. The alias Int is also supported.

variables:
- name: integer
type: Integer
min: 0
max: 100
anyOf: [1, 2]
noneOf: [3]

If no constraints are provided, the generated value will be between 0 and 100.

Example value:

11

Float

Generates a 64-bit floating point value.

variables:
- name: float
type: Float
min: 0.0
max: 100.0
anyOf: [1.2, 3.4]
noneOf: [5.6]

If no constraints are provided, the generated value will be between 0 and 100, with up to 3 decimal places.

Example value:

42.701

String

Generates a string value.

variables:
- name: string
type: String
length: 5
minLength: 5
maxLength: 10
anyOf: ["this", "that"]
noneOf: ["notthis"]

If no constraints are provided, the generated value will be an alphabetic string between 5 and 20 characters in length.

Example value:

"AytMv"

Name

Generates a full name, as a given name and surname separated by a single space.

variables:
- name: name
type: Name

Example value:

"Patricia Smith"

Email

Generates an email address with an example.com, example.net, or example.org domain.

variables:
- name: email
type: Email

Example value:

"JLWPHdTPtMO@example.net"

Date

Generates a date.

For details on format syntax, see the Full Format page.

variables:
- name: date
type: Date
min: "2024-01-01"
max: "2024-12-31"
anyOf: ["2024-01-01", "2024-02-01"]
noneOf: ["2024-02-29"]
format: "%Y-%m-%d"

If no constraints are provided, the generated value will be between 1970-01-01 and the current date. The default format is YYYY-MM-DD.

Example value:

"2010-04-21"

DateTime

Generates a date time (timestamp).

For details on format syntax, see the Full Format page.

variables:
- name: datetime
type: DateTime
min: "2024-01-01 00:00:00"
max: "2024-12-31 23:59:59"
anyOf: ["2024-01-01 00:00:00", "2024-02-01 00:00:00"]
noneOf: ["2024-02-29 00:00:00"]
format: "%Y-%m-%d %H:%M:%S"

If no constraints are provided, the generated value will be between 1970-01-01 and the current date and time. The default format is YYYY-MM-DD hh:mm:ss.

Example value:

"2023-01-30 23:13:42"

List

Generates a list.

variables:
- name: list
type: List
length: 5
minLength: 5
maxLength: 10
schema:
type: String
length: 10

If no schema or constraints are provided, the generated value will be a list of integers with between 1 and 10 items, where each item is between 0 and 100.

Example value:

[98,38,3,31]

Object

Generates an object.

variables:
- name: object
type: Object
schema:
"field1": "value"
"field2":
type: Integer
min: 0
max: 100

This type has no default value, so schema is required.