Has anyone been using a .NET mocking framework that they have found compatible with Monotouch? I am curious about compatibility with NMock, NSubstitute, Moq and other frameworks before I attempt to use one.
Xamarin just beefed up its unit testing support, but no mention of a mock framework. FYI, I am hoping to do a lot of my development on VS 2010 for the non-UI bits and move to the iOS platform when the UI comes into play.
Thanks for the help.
What is a mocking framework? Mocking frameworks are used to generate replacement objects like Stubs and Mocks. Mocking frameworks complement unit testing frameworks by isolating dependencies but are not substitutes for unit testing frameworks.
Mocking Frameworks (Moq, NSubstitute, Rhino Mocks, FakeItEasy, and NMock3) are used to create fake objects. We can stub, i.e., completely replace the body of member and function. It is used to isolate each dependency and help developers in performing unit testing in a concise, quick, and reliable way.
Verify methods were called Mocking frameworks add another way to test - checking whether methods were called, in which order, how many times and with which arguments. For example, let's say that a new test is required for adding a new user: if that user does not exist than call IDataAccess. AddNewUser method.
I would recommend just using manual mocking:
interface IClass {
void Method(int x);
}
MockClass : IClass {
public void Method(int x) {
MethodParameter = x;
}
//Assert against this guy
public int MethodParameter { get; private set; }
}
StubClass : IClass {
public void Method(int x) {
//Do nothing
}
}
If I had to guess Rhino Mocks, Moq, etc. have heavy usage of Reflection.Emit (how else could you do the craziness they can do?), which will not run with the AOT compiler on MonoTouch.
Try TrueFakes! It can mock public interfaces.
Try TrueFakes! It can mock public interfaces.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With