liveBook · Manning

Parameterized testing

As explained in Unit Testing Principles, Practices, and Patterns

A parameterized test is a test whose logic is executed with multiple sets of input values or expected results.

Parameterized testing runs one test logic with multiple input and expected-result sets. It groups similar facts about a unit’s behavior, reducing duplicated test code. section 3.5

Use it when:

  • Several tests differ only in their input values or expected results. section 3.5
  • Each data row represents a separate fact, while the test method supplies shared execution logic. section 3.5
  • Keep separately named tests when descriptive scenario names matter more than reducing code, especially for positive cases. section 3.5

Delivery-date validation

A theory can test -1, 0, 1, and 2 days from now with expected results false, false, false, and true. Simple rows fit InlineData; complex cases can come from generated member data. section 3.5

Figure 3.2. A typical application exhibits multiple behaviors. The greater the complexity of the behavior, the more facts are required to fully describe it. Each fact is represented by a test. Similar facts can be grouped into a single test method using parameterized tests.

Use the figure to distinguish individual behavioral facts from similar facts grouped into one parameterized test. section 3.5

How Unit Testing Principles, Practices, and Patterns covers it

How deep it goes
Explains data rows, theories, InlineData, complex member data, and readability trade-offs without descending into framework internals.
Examples
Uses delivery-date validation with dates from yesterday through two days ahead and Boolean validity results.
What it assumes
Assumes basic unit-testing knowledge and teaches grouping repeated scenarios through framework-supported test data.
What you can do after
Apply it via xUnit to consolidate similar tests while preserving separate names for especially important scenarios.
How it connects
Connects unit tests, test cases, theories, xUnit, and assertions.

Also explained in

Compare how 2 books explain parameterized testing →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Unit Testing Principles, Practices, and Patterns. The section links point to the parts of the book it draws on.