Green Bar Patterns in Test-Driven Development

200-901 By islever Editorial Last updated

Short answer

CE Fake it and triangulate are recognized Green Bar patterns in Test-Driven Development used to achieve passing tests incrementally.

Question

In test-driven development, what are two of the green bar patterns? (Choose two.)
  1. another test
  2. break
  3. triangulate Correct Answer
  4. starter test
  5. fake it Correct Answer

Key Takeaways

Fake it and triangulate are core Green Bar patterns in Test-Driven Development (TDD). Fake it involves returning constants to pass tests initially, while triangulate uses multiple test cases to drive generalized code solutions.

Expert Analysis

Green bar patterns in TDD describe strategies used after a test passes (green bar). "Fake it" means returning a constant to make the test pass, then gradually generalizing. "Triangulate" means using multiple test cases to drive a general solution.

Test-Driven Development (TDD) is a software development methodology where tests are written before the implementation code. The process is often visualized as a cycle: Red (failing test), Green (passing test), and Refactor (cleaning up code). Within this cycle, specific patterns or heuristics guide the developer on how to move from a failing state to a passing one efficiently without over-engineering the initial solution. These patterns are particularly relevant when dealing with simple requirements or stubbing out dependencies.

The correct options are Fake it and Triangulate. These are two of the most fundamental "Green Bar Patterns" described in Kent Beck's Test-Driven Development by Example.

Fake it is the strategy employed when the simplest way to make a test pass is to return a hardcoded value. For example, if you have a test expecting get_total to return 10, and the underlying logic is complex, you might simply write return 10. This immediately turns the red bar green. While this seems like cheating, it serves a critical purpose: it confirms that the test infrastructure works, the build process is correct, and the test itself is valid. Once the test is green via a fake, the developer can then refactor or add more complex logic, knowing they have a safety net. The key constraint here is that the fake must be temporary; it is a stepping stone, not the final solution.

Triangulate is the pattern used when a single test case is insufficient to drive the generalization of the code. After making a test pass (perhaps via "Fake it" or a minimal implementation), the developer adds a second, different test case that expects a different outcome. If the existing code (which passed the first test) fails the second test, the developer is forced to generalize the logic to satisfy both cases. For instance, if the first test expected add(1, 1) to return 2 and was faked, adding a second test for add(2, 3) expecting 5 would break the fake. The developer must then implement actual addition logic. Triangulation ensures that the code evolves based on concrete evidence rather than assumptions about what the "correct" implementation looks like.

Let's analyze why the other options are incorrect in this context:

  • Another test: While writing additional tests is part of TDD, "another test" is not a named pattern for achieving the green bar. It is an action, not a strategic heuristic for implementation.
  • Break: Breaking code is antithetical to TDD. The goal is to maintain functionality while extending it. Deliberately breaking code would result in a red bar, which is the starting point, not a pattern for reaching green.

Starter test: A "starter test" is a type of test written at the beginning of a feature, but it is not a pattern for how* to make the test pass. It is a unit of work, not a mechanism for code construction during the Green phase.

Understanding these patterns is crucial for efficient TDD. They prevent developers from getting stuck trying to write perfect code immediately and instead encourage incremental progress. "Fake it" allows quick validation of the test harness, while "Triangulate" drives the evolution of the logic through concrete examples. Other patterns exist, such as "Simplest Thing Possible" or "Refactor," but "Fake it" and "Triangulate" are specifically identified as core strategies for transitioning from Red to Green in standard TDD literature.

Exam Strategy

When facing questions about TDD methodologies, look for keywords related to incremental implementation strategies. Focus on patterns that describe how to make a test pass quickly (like faking or simplifying) versus patterns that describe what to test. Memorize the specific named patterns from authoritative sources like Kent Beck's TDD book, as exam questions often directly reference these established terms rather than generic descriptions.

Practice All 200-901 Questions

Access 105 questions with complete answers and detailed explanations.

View Full 200-901 Practice Test →

← Back to 200-901 Study Guide