5

Having read good things about Moles I'd like to add an isolation framework to our set of tools for writing unit tests.

Our application runs under Mono as it is deployed on both Linux and Windows and I cannot seem to find a framework that supports Mono.

I've seen some articles about manipulating assemblies using Cecil but I'm struggling to find anything we could realistically use.

sebjsmith
  • 71
  • 5

2 Answers2

4

Looks like Moles works using the JIT, so I'd expect it to be very very tied to microsoft's implementation.

I've had a fantastic amount of success using Moq on mono, With a very small amount of effort it is possible to create a proxy instance of almost any class and intercept nearly all method calls. The latest binary version of Moq works very well on mono for me.

using Moq;

var mock = new Mock<MyClass> { CallBase = true };
mock.Setup( x => x.MyMethod() ).Returns ( 1 );

After using Moq to setup things I generally prefer to use NUnit but you can use any other test framework.

IanNorton
  • 7,145
  • 2
  • 25
  • 28
  • Thanks for your input, Ian. Yes, I've not even tried to look at running Moles with Mono as I assume that it is going to fail. We are already using Moq, which I think is fantastic but I'm looking for tools that allow me cope with DateTime.Now type issues. I'm fully aware I can wrap static methods behind instance methods in proxy classes but I'm not sure that it is the most elegant solution in all scenarios. – sebjsmith Jan 05 '12 at 20:29
  • Have you looked at using PostSharp to add pre/post hooks to your methods? – IanNorton Jan 05 '12 at 20:57
  • No, I've not. Could you give me an example of how that could help? Thanks in advance. – sebjsmith Jan 09 '12 at 15:08
0

TypeMock is most likely your only choice when adding in your comments on the answer from @IanNorton .

Chris Marisic
  • 32,487
  • 24
  • 164
  • 258