liveBook · Manning

Test data generation

As explained in Data-Oriented Programming in Java

A test data generator is a mechanism that produces input values or cases for testing software according to defined generation rules.

Test data generation produces input values or cases from defined rules, replacing hand-written examples with controlled randomized data. A single randomized function can feed Java streams indefinitely, while specialized generators keep business-relevant states visible. section 11.5.1 section 11.5.2

Useful generation patterns include:

  • Generate specialized collections, such as accounts from one region or accounts fixed to a particular identifier. section 11.5.1
  • Combine focused generators to cover meaningful partitions, such as values above, equal to, or below a threshold. section 11.5.2
  • Generate a broad collection first, then filter or group it into interesting subsets. section 11.5.1
  • Randomize collection sizes, including zero, and nest generators to produce structures such as lists of lists. section 11.5.1
  • Adjust the amount of generated data to reuse one test for ordinary checks, load exploration, throughput, or service-duration questions. section 11.5.3

Testing threshold behavior

Choose a random threshold, generate accounts above, at, and below it, and combine those streams into one set. The test can then assert that accounts above the threshold in a region are excluded while the other generated states are processed. section 11.5.2

Listing 11.38 The Stream.generate function
public static<T> Stream<T> generate(Supplier<? extends T> s) {...}  #A

Stream.generate accepts a supplier and creates the source stream used by the constrained, combined, and volume-controlled generation patterns. section 11.5.1

How Data-Oriented Programming in Java covers it

How deep it goes
Explains Stream.generate, specialization, combination, filtering, nesting, random sizes, and state partitioning without detailing generator internals.
Examples
Uses randomized accounts, regional subsets, threshold states, empty collections, nested lists, CSV payloads, and mirror-state tests.
What you can do after
Apply it via Java Stream.generate to construct targeted test cases, expose edge states, and scale inputs for workload experiments.
How it connects
Connects randomized testing with property testing, invariant checking, integration testing, load testing, and Java streams.

Also explained in

Compare how 2 books explain test data generation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data-Oriented Programming in Java. The section links point to the parts of the book it draws on.