What should you test?
I just found myself writing this:
[Test]
public void When_resolving_using_framework_element_will_create_layout_using_resolver()
{
}
The code that I want to test looks something like this:
public void Register(FrameworkElement frameworkElement)
{
Register(layoutDeocratorResolver.GetLayoutDecoratorFor(frameworkElement));
}
public void Register(ILayout layout)
{
if (layouts.ContainsKey(layout.Name))
throw new DuplicateLayoutException("Layout names must be unique. A layout named '" +
layout.Name + "' already exists.");
layouts.Add(layout.Name, layout);
}
The problem that I have here is that it looks like I am trying to specify the mechanics of the code under test, and that is a big mistake. I really should not care how it is doing it. I should care about the results. Therefor, I decided to change the test to:
[Test]
public void When_resolving_using_framework_element_will_add_layout_decorator_for_that_element()
{
}
Now what I am testing is behavior, not mechanics.
Tests that validate the mechanics of the code are brittle, and end up as testing shackles.