I’ve recently been working on a project trying to use xUnit.net and I’m really pleasantly surprised by one thing…. the change in vocabulary. No longer do we have tests we have facts. It may seem to some that this change means very little (Apart from making it really hard to swap out xUnit.net and put in Nunit or mbUnit which both use a common syntax to mark a test. However to me it comes down to how the act of unit testing is interpreted, rather than stating a test about the whole system we are combining our unit tests into a set of hypothesis and proofs around how the system works, which when executed help us to determine a level of confidence over how well our software helps achieve certain goals.
Phil Haack has had a recent number of posts about some of the misconceptions about what unit testing achieves
But also recently with my unit testing I’ve been put into new teams and worked with colleagues who I’ve never had the pleasure of working with…. now not too long ago I was merrily coding away when one of them noticed my (liberal) use of the
framework and blankly stated that he never used mocks and didn’t really like them.
I suddenly realised that I’ve become a very mockist developer. Let me explain, there are two camps when it comes to mock frameworks, those who use them (mockists) and those who don’t (classicists)
Now I’m firmly in the mockist camp, and my whole work pattern has revolved around them, I will often code to interfaces by default and do the very minimum possible to get a function working with mocks, I find it really helps me to focus on the unit in question without having to fill out every single layer to test every permutation of circumstances.
I will code a test for a method, start to write the code, and using Dependency Injection work out what pieces of data should be coming from other layers and use mocks to achieve this. There is one caveat, the tests don’t cover end to end functionality so there is a danger that maybe the tests really don’t cover real life scenarios, however I would hope that I would get this kind of coverage from my front end WatIn
tests. So speed and focus are why I’m firmly in the mockist camp, however I do wish I could do something like this.
IItem mockItem = mockRepository.CreateMock(); Expect.Call(mockItem.TestMethod()).Returns(somevalue).RealCodeCoveredByTest(TestThatTestMethodReturnsSomeValue)
or maybe get resharper to generate the stub of that test? anyway it’s just because i’m lazy. but I guess that’s what testing with coverage is for.
Technorati Tags: Agile, mockist, RhinoMocks, tdd, xUnit.net