开发者

Open Source / Free alternative of Typemock Isolator

开发者 https://www.devze.com 2023-02-22 11:48 出处:网络
Is there 开发者_开发问答any F/OSS alternative of Typemock Isolator .NET?Disclaimer: I work at Typemock

Is there 开发者_开发问答any F/OSS alternative of Typemock Isolator .NET?


Disclaimer: I work at Typemock

Typemock Isolator utilizes the CLR Profiler API to perform IL rewriting, thus allowing you to fake (mock) static methods and concrete classes. As far as I know, Moles does similar things to Isolator in terms of using the Profiler to mock those things, and it's free (but not open source).

All other open source frameworks using the Dynamic Proxy to implement interfaces and abstract classes in runtime, therefore they cannot mock sealed/static classes.


I'm not familiar with all of the features of Typemock Isolator, but Moles is a free product that I've used for unit testing.


I have used Typemock in my last project and am very happy with it. I went through the same pain of getting approval to purchase Typemock in my organization because of its cost. But in the end we were happy with our purchase.

I recently came across JustMock which is developed by Telerik. It can mock almost anything like Typemock and is also cheaper than Typemock, which is good. The better part is, they have a trimmed version of their product - JustMock Lite which is free. You can get started with the free version and then upgrade to the paid version if you need the advanced features like mocking sealed classes, non-virtual methods etc. That way you do not have to change your code when you upgrade to support advanced mocking scenarios.

Also JustMock uses Dynamic Proxy approach for simple mocking scenario's like interfaces, virtual methods and uses .NET profiling API only for the advanced features making the unit tests run faster for the simplest scenarios.


I have created one - AutoFake. So you can replace whatever you want without a need to pay some money and with an opportunity to have a fast support from the opensource community. Here is a short example of what you can do:

public class Calendar
{
    public static DateTime Yesterday => DateTime.Now.AddDays(-1);
}

[Fact]
public void Yesterday_SomeDay_ThePrevDay()
{
    var fake = new Fake<Calendar>();

    var sut = fake.Rewrite(() => Calendar.Yesterday);
    sut.Replace(() => DateTime.Now).Return(new DateTime(2016, 8, day: 8));

    Assert.Equal(new DateTime(2016, 8, 7), sut.Execute());
}


I use Moq mocking library in my tests for mocking purposes. It's completely F/OSS (BSD license).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号