简体   繁体   English

用于测试Mono的隔离框架

[英]Isolation framework for testing for Mono

Having read good things about Moles I'd like to add an isolation framework to our set of tools for writing unit tests. 阅读了关于Moles的好东西后,我想在我们用于编写单元测试的工具集中添加一个隔离框架。

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. 我们的应用程序在Mono下运行,因为它部署在Linux和Windows上,我似乎找不到支持Mono的框架。

I've seen some articles about manipulating assemblies using Cecil but I'm struggling to find anything we could realistically use. 我已经看过一些关于使用塞西尔操纵装配的文章,但我很难找到任何我们可以实际使用的东西。

Looks like Moles works using the JIT, so I'd expect it to be very very tied to microsoft's implementation. 看起来Moles使用JIT工作,所以我希望它与microsoft的实现非常紧密相关。

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. 我在单声道上使用Moq获得了巨大的成功,只需很少的努力就可以创建几乎任何类的代理实例并拦截几乎所有的方法调用。 The latest binary version of Moq works very well on mono for me. 最新的Moq 二进制版本对我来说非常适合单声道。

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. 使用Moq设置后我通常更喜欢使用NUnit,但您可以使用任何其他测试框架。

在对@IanNorton的答案添加评论时,TypeMock很可能是您唯一的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM