liveBook · Manning

Schema-based unit test

As explained in Data-Oriented Programming: Reduce software complexity

A schema-based unit test is an automated test that generates arguments conforming to an input schema and checks that the result conforms to an output schema.

A schema-based unit test generates arguments that conform to an input schema, calls the function, and checks whether the result conforms to an output schema. It replaces hand-picked examples with varied generated data while keeping the contract explicit. section 12.5

A practical test flow is:

  • Generate data with JSON Schema Faker, from a UUID to a nested catalog. section 12.5
  • Call the function with generated arguments and validate its return value against the response schema. section 12.5

Searching generated catalogs

A refined test selects the first generated book, searches for its first title character, and returns false on an exception. The failure identifies invalid authorNames values; correcting the fallback makes the test pass.

Figure 12.3 The flow of a schema-based unit test

Follow the diagram to see generated arguments, function execution, and return-schema validation as one testing loop. section 12.5

How Data-Oriented Programming: Reduce software complexity covers it

How deep it goes
Demonstrates generation, execution, validation, diagnostics, and repair, stopping short of broader test-suite design.
Examples
Generates UUIDs and catalogs, then tests Catalog.searchBooksByTitle with generated queries and schema validation.
What it assumes
Assumes defined argument and return schemas while teaching the testing flow and generated-data technique from the unit-test idea.
What you can do after
Diagnose implementation bugs by running generated contract checks and inspecting validation failures.
How it connects
Connects data schemas with unit testing, input validation, output validation, and automated test-data generation.

Related concepts

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