liveBook · Manning

Triangulation

As explained in Test Driven: Practical TDD and Acceptance TDD for Java Developers

Triangulation is a test-driven development technique that adds tests with varied inputs to progressively constrain the required implementation.

When a hard-coded implementation passes one test but its proper generalization is unclear, add tests with different inputs. Each new failing test narrows the behavior the implementation must support. section 2.2.4 section 4.1.2

Evolving a template renderer

Suppose a template should render a name. Add a second set call with a different value and assert the new result; the hard-coded answer fails. Store the value to pass, then vary the surrounding template text to expose the remaining literal output and reveal the need to parse the template. section 2.2.4

Listing 2.8. Making the second test pass by storing and returning the set value
public class Template { private String variableValue; public Template(String templateText) { } public void set(String variable, String value) { this.variableValue = value; } public String evaluate() { return "Hello, " + variableValue; } }

See the interim Java implementation: it stores the set value but still hard-codes the greeting prefix. section 2.2.4

How Test Driven: Practical TDD and Acceptance TDD for Java Developers covers it

How deep it goes
Demonstrates successive test changes and minimal implementations, stopping when template parsing becomes the next challenge.
Examples
Uses a Java template renderer whose changing name values and surrounding template text expose hard-coded output.
What you can do after
Apply it by adding failing tests with varied inputs to drive hard-coded behavior toward a more general implementation.
How it connects
Connects test-driven development with failing tests, hard-coded implementations, and faking it.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Test Driven: Practical TDD and Acceptance TDD for Java Developers. The section links point to the parts of the book it draws on.