• Decrease Integration Test maintenability cost
  • Baby step to BDD by injecting context (Given)
  • Integration test / BDD can now run into a build server
  • Seat belt when refactoring on Legacy
  • Decrease the cost of first tests on Legacy
  • Other Refactoring interesting tool : Resharper, NFluent



TDD is dead : only for legacy code that doesn't have HardMock!

TDD is a good method in order to build an application corresponding exactly to acceptance tests.

Imagine a legacy project without test or manual test and you have to add feature
using TDD. It is just impossible!


Because we have to apply red green refactor.

On Legacy code, you can spent 1 week to write a test because you have to mock a lot of dependencies (mock with any mock framework).

It's very stupid for ROI purpose to spend 1 week for a test that you delete when the refactoring is done.
I prefer write test during 1 hour and then refactor during 1 week.

Why don't you write an integration test which call real services, real databases, ...

It's more easy to write an integration test instead of write unit test but...

What's append if the data of this dependencies impact assertions? If another developper change the data with another test?

What's append when you checkin this test? It fail often because the build account doesn't have persmissions, or database server os down...
But when you refactor legacy code you checkin every day or hour or minutes.

When you run your test automatically like ncrunch your test must be fast and Integration tests are slow.

Then refactoring during more than one days...

Hard mock can produce mock based on integration test by recording dependencies from integration tests for generating mock at run time.

When use it?

When you spend more than 1 hour to produce first test.


You must use HardMock only for producing first test on legacy code in order to refactor and produce real unit test with manual, framework based mock like MoQ, RhinoMocks or FakeItEasy


First write your integration test in a Unit Test.
Write your assertions
Then extract interface for every dependencies of your target class.
Add the recorder behavior for every dependencies using AsRecord extension method.
In the end of test write your recorded mock to a file using Snapshot extension method.
To increase user experience use NFluent to discover assertion more quickly by copy/paste from exception message what has been expected.

Now you have a mock stored into a file and you can replay using BuildMockFrom extension method.
Now you can checkin your test and refactor your code.

Into source code, there is AcceptanceTest project which contains all sample. See Demo.cs first

Last edited May 14, 2014 at 11:28 AM by cboudereau, version 13