liveBook · Manning

Chapter 11: Data Oriented Testing

What you will learn in chapter 11 of Data-Oriented Programming in Java

The chapter introduces data-oriented testing and emphasizes that how tests represent data affects their clarity.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The chapter introduces data-oriented testing and emphasizes that how tests represent data affects their clarity.

Key terms: representation, understandability

11.1 A few definitions

This section defines how the book uses the terms unit test, integration test, and mock.

Key terms: Unit Tests, Integration Tests, isolation, dependencies, IO, Mock, stub, shim, proxy

11.2 Data orientation makes tests better

This section shows how data-oriented code makes tests simpler and more flexible by separating behavior from dependencies and treating test inputs and outputs as data.

Key terms: pure, deterministic functions, inputs and outputs, non-determinism, mocking, side-effects, brittleness, FileRepository, functional core, imperative shell, CSV

11.3 Writing data-oriented tests

The section explains what good tests communicate and how brittle, opaque, narrowly focused tests fall short.

Key terms: test suite, domain, invariants, regression, bad tests, code path, coverage metric

11.3.1 Use data to show what’s under test

The section shows how to make a test explain its expected result by putting relevant input data and assertions together.

Key terms: causal link, inputs, assertions, data, shared setup methods, local reasoning, factory functions, test data, Account, threshold

11.3.2 Data makes tests flexible

The section shows how data-driven tests can vary inputs, expose weaknesses in assertions, and generate many scenarios automatically.

Key terms: threshold, hard-coded constants, data oriented tests, sets, comparison operator, Discounts, shouldBeProcessed, power set, subsets, data-oriented tests

11.3.3 Model side-effects with data

This section explains how data-driven tests can describe and verify side-effects even when a method returns nothing useful.

Key terms: side-effects, data, mocking

11.3.4 Don’t be afraid to introduce new data types

This section argues that tests can use data types to describe meaningful system states and expected behavior, even when the code under test consists entirely of side effects.

Key terms: data modeling, data types, lifecycles, state of the system, branch coverage, domain, semantic level

11.4 Avoiding common problems in test suites

This section shows how hard-coded shared test data creates hidden coupling and argues for keeping useful helpers while removing the hard coding.

Key terms: coupling, hard coded data, helper functions, shared test data, shared helper functions, hard coding, test data

11.4.1 Randomize unused inputs to prevent coupling

This section explains how randomizing unspecified test inputs prevents hidden coupling and tests the assumption that those inputs do not affect the asserted behavior.

Key terms: helper functions, hard coded values, randomized test data, coupling, Withers, overloaded functions, randomized data, randomizing data, assertions, all possible values

11.5 Using randomized data in tests

This section explains why randomized test data can explore program states that example-based tests often miss.

Key terms: data type, possible values, possible states, example, randomized data, hard-coded state, algebraic style of reasoning, randomizer

11.5.1 Streams + randomization = infinite test data

The section shows how randomized generators and Java streams can produce varied test data, including combined cases, empty collections, and nested inputs.

Key terms: Stream.generate, randomized data, specialized collections, generators, Stream.concat, interesting subsets, for all, randomize the amount of data, edge cases, Lists of Lists of Accounts

11.5.2 Exercise all the states in your program

This section shows how to use randomized test data to exercise the states relevant to a test’s invariant, rather than relying on a few hand-picked examples.

Key terms: states, randomized data, threshold, invariant, generators, spend(), moving from specific to general, moving from general to specific, concat, equality case

11.5.3 One test, multiple roles

Generated data lets one test serve different purposes by changing how many inputs it runs against.

Key terms: generating data, unit test, load test, generators

11.5.4 The most useful tests are often the simplest

This section explains how simple randomized round-trip tests can expose data-handling problems at system boundaries.

Key terms: randomized test data, round-trip, system boundaries, serialization

11.5.5 Verifying algebraic properties.

This section explains how randomized examples can give confidence in algebraic properties when a data type has too many possible states to test exhaustively.

Key terms: algebraic laws, state space, randomizer, String, BigDecimal

11.5.6 Randomization is just another tool

This section explains when randomized testing helps, when deterministic examples are better, and how test failures can guide the choice.

Key terms: randomized test data, determinism, mock, hard code data, interesting states, algebraic property, randomized data, generative power, bugs sneaking through your suite, generator

11.5.7 Favor using libraries when generating data

This section explains why hand-written randomization is a useful starting point for tests but libraries are preferable as randomized testing grows more sophisticated.

Key terms: randomization, libraries, testing style, repeatable randomization, seed, distribution, edge cases, debuggability

11.6 A few closing thoughts on testing

This section argues that testing strategies should fit the software and explains the complementary strengths and limits of unit and integration tests.

Key terms: testing pyramid, testing “shape”, unit tests, integration tests, mocks, outside world

11.6.1 Data coverage is more important than test coverage

This section argues that useful test data and meaningful assertions matter more than a code-coverage percentage.

Key terms: coverage, domain and its properties, confidence, data coverage, consumers of data

11.6.2 Embrace the humble comment

This section explains why narrative comments make tests easier to understand by revealing the purpose and hidden context that test code alone may not show.

Key terms: narrative, comments, institutional knowledge

11.6.3 The best tests are the ones you don’t have to write

Better modeling can eliminate tests by making invalid states impossible to express.

Key terms: invariants, type system, NonEmpty, NonNegative

11.7 Wrapping up

The section closes by summarizing data-oriented testing as putting what you know into tests, driving them with data, and letting the computer do much of the work.

Key terms: data-oriented testing, data

11.8 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 10: Data Oriented Architecture Chapter 12: Integration Testing →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.