Today I was writing some tests (as I do every day), and I wrote this.
[Test]
public void IfLanguageChangesToNlWhenbtnDutchIsClicked()
{
var _mocks = new StructureMap.AutoMocking.RhinoAutoMocker<FrmMenu>();
var _menu = _mocks.ClassUnderTest;
var language = _mocks.Get<ILanguageSettings>();
language.Expect(x => x.Language)
.Return(Enumerations.Languageoptions.nl);
_menu.btnDutch.RaiseClick();
Assert.AreEqual(Enumerations.Languageoptions.nl,language.Language);
}```
I used [Rhino mocks][1] for this.
FrmMenu has these three buttons.
```vbnet
''' <summary>
Private Sub btnDutch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDutch.Click
Me.Language.Language = Enumerations.Languageoptions.nl
End Sub
So the test should check if the language changes to dutch when I clikc that button.
But I’m not testing my code I’m testing [Rhino mocks][1]. And that can never be the point. Because that test will always pass (unless [Ayende][2] did something really stupid)
I rewrote the test like this.
[Test]
public void IfLanguageChangesToNlWhenbtnDutchIsClicked()
{
var _mocks = new StructureMap.AutoMocking.RhinoAutoMocker<FrmMenu>();
var _menu = _mocks.ClassUnderTest;
var language = _mocks.Get<ILanguageSettings>();
_menu.btnDutch.RaiseClick();
language.AssertWasCalled(x => x.Language = Enumerations.Languageoptions.nl);
}```
And now I’m testing the right thing.
[1]: http://www.ayende.com/projects/rhino-mocks.aspx
[2]: http://www.ayende.com