Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mocking frameworks for .NET on Monotouch?

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.

like image 246
Nekoashi Avatar asked Feb 28 '12 21:02

Nekoashi


People also ask

What are mocking frameworks?

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.

Which of the following are mocking framework?

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.

How is a mocking framework used for verification?

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.


3 Answers

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.

like image 135
jonathanpeppers Avatar answered Sep 22 '22 14:09

jonathanpeppers


Try TrueFakes! It can mock public interfaces.

like image 25
Max Polkovnik Avatar answered Sep 25 '22 14:09

Max Polkovnik


Try TrueFakes! It can mock public interfaces.

like image 36
Max Polkovnik Avatar answered Sep 26 '22 14:09

Max Polkovnik