liveBook · Manning

Implicit input

As explained in Unit Testing Principles, Practices, and Patterns

A hidden input is an implicit dependency on internal or external state that affects a computation without appearing as an explicit argument.

An implicit input is internal or external state that affects a computation without appearing as an explicit method argument. References to mutable state and dependencies such as databases are hidden inputs. section 6.3 section 6.6

Implicit inputs matter because they change both design and testing:

  • They prevent a method from behaving as a mathematical function, because identical explicit arguments may produce different results. section 6.3
  • They block output-based testing, whose strongest maintainability depends on having no hidden inputs or outputs. section 6.6
  • They create a trade-off: gather possible data up front for stronger separation, or let an application service decide when to query it for better performance. section 6.5

Database dependency in AddRecord

Passing an IDatabase instance to AddRecord introduces a hidden input through external state. Gathering access data before the decision preserves a functional core but may perform unnecessary queries; delegating the query decision to the application service improves performance while weakening separation. section 6.5

public FileUpdate AddRecord(
    FileContent[] files, string visitorName,
    DateTime timeOfVisit, IDatabase database
)


!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":2,\"ch\":26},{\"line\":2,\"ch\":44}]]"}
!@%STYLE%@!

Inspect the method signature that exposes the database dependency and reveals how external state enters the computation. section 6.5

How Unit Testing Principles, Practices, and Patterns covers it

How deep it goes
Explains the definition, testing consequence, and database refactoring trade-off, but stops short of implementation details beyond the method signature.
Examples
Uses Increment with internal state and AuditManager.AddRecord with a database dependency to contrast explicit and hidden inputs.
What it assumes
Assumes familiarity with method signatures, unit-testing styles, application services, and external dependencies.
What you can do after
Diagnose hidden dependencies, predict when output-based testing becomes unavailable, and choose between eager data gathering and delegated lookup.
How it connects
Links implicit inputs to pure functions, output-based testing, functional architecture, side effects, application services, and separation of concerns.

Also explained in

Compare how 2 books explain implicit input →

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.