I finally took some time today to explore NMock with a collegue. We wanted to unit test a .NET component that was consuming some COM interfaces. This is difficult, since the instances we are dealing with are created by another process, and they are not createable outside that environment. “Mocking” allows us to create an object that looks and behaves like the desired component for a specific condition, as well as provide an indication if the object under test behaved in the expected way.
NMock provides a full framework for mocking, and works well with NUnit, a top-notch unit testing framework. While seeing a great potential for usefulness and making unit testing less painful, I was sad to see that there are some issues that kept it from working in our case:
- Practically zero documentation - No official documentation, some ambiguous samples here and there. You can use the jMock documentation to learn concepts, but NMock is hardly a transparent port to the CLR.
- Some issues with mocking interfaces - It doesn't seem to recognize inherited members.
- Some issues with COMInterop - This was what made #2 a show stopper. It was trying to instantiate a COM object when all we wanted was to mock it.
We'll screw with it some more in the next week or so before giving up. There seems to be much more recent code in SourceForge than is released. Maybe some of the issues are fixed.