liveBook · Manning

Test

As explained in Data-Oriented Programming: Reduce software complexity

A test case is a specific set of input data, execution conditions, and expected results used to evaluate software behavior.

A test case specifies input data, execution conditions, and expected results for evaluating software behavior. For data-oriented functions, the pattern is refreshingly direct: supply data, run the function, and compare the returned data with the expected data. section 6.0 section 6.1

Build a data-oriented test case in three moves:

  • Generate the input data, such as catalog data and an array of author IDs. section 6.1
  • Generate the expected output data. section 6.1
  • Compare the function result with the expected output, recursively comparing collections by value rather than reference. section 6.1

Test quantity should follow the function-call tree. Lower-level functions usually handle simpler data and need more cases; higher-level functions can use a minimal case when their called functions are already covered. section 6.2.3 section 6.6

Testing Catalog.authorNames

Use a minimal catalog and test an empty ID list, one known author, multiple known authors, missing catalog data, and nonexistent author IDs. Compare each returned array with its expected array using _.isEqual. section 6.2.2

Listing 6.3 The general pattern of a data-oriented test case
var dataIn = {
  // input
};
 
var dataOut = {
  // expected output
};
 
_.isEqual(f(dataIn), dataOut);

The general pattern makes the test case executable: define dataIn, define dataOut, and compare _.isEqual(f(dataIn), dataOut). section 6.1

How Data-Oriented Programming: Reduce software complexity covers it

How deep it goes
Defines a three-step pattern and calibrates case quantity by function-call depth, while deferring test runners and frameworks.
Examples
Uses catalog author-name queries, empty and missing data, nonexistent authors, and book-information records.
What it assumes
Assumes familiarity with functions and data collections while teaching input generation, expected output, and recursive comparison directly.
What you can do after
Build test cases from scratch for data-oriented queries and mutations using generated inputs, expected outputs, and recursive comparison.
How it connects
Connects test cases to unit testing, data manipulation, recursive comparison, function-call trees, queries, and mutations.

Also explained in

Compare how 53 books explain test →

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.