I’ve been hearing about the London style vs. Chicago style (sometimes called Detroit style) of Test Driven Development (TDD).

Workshop of Utah Extreme Programming User's Group:


  Interaction-style TDD is also called mockist-style, or London-style after London's Extreme Tuesday club where it became popular. It is usually contrasted with Detroit-style or classic
  TDD which is more state-based.


Jason Gorman's workshop:


  The workshop covers both the Chicago school of TDD (state-based
  behaviour testing and triangulation), and the London school, which
  focuses more on interaction testing, mocking and end-to-end TDD, with
  particular emphasis on Responsibility-Driven Design and the Tell,
  Don't Ask approach to OO recently re-popularized by Steve Freeman's
  and Nat Pryce's excellent Growing Object-Oriented Software Guided By
  Tests book.


The post Classic TDD or "London School"? by Jason Gorman was helpful, but his examples confused me, because he uses two different examples instead of one example with both approaches. What are the differences? When do you use each style?

Suppose you have class called "ledger" a method called "calculate" that uses a "Calculator" to do different types of calculations depending on the arguments passed to "calculate", for example "multiply(x, y)" or "subtract(x, y)".

Now, suppose you want to test what happens when you call ledger.calculate("5 * 7").  

The London/Interaction school would have you assert whether Calculator.multiply(5,7) got called.  The various mocking frameworks are useful for this, and it can be very useful if, for example, you don't have ownership of the "Calculator" object (suppose it is an external component or service that you cannot test directly, but you do know you have to call in a particular way).

The Chicago/State school would have you assert whether the result is 35. The jUnit/nUnit frameworks are generally geared towards doing this.

Both are valid and important tests.
