3

What are the few good and free unit-testing alternatives to Telerik JustMock library/tool for unit-testing in C#.

Here, I wish to know alternative not just for JustMock lite but for paid JustMock version providing elevated mocking features (like mocking static, final, sealed, extension methods) etc.

1

Not ideal, and not completely free, but if you have Visual Studio Premium or Ultimate, there is Microsoft Fakes included in it, which is another profiler-based mocking framework, providing such features. It cannot be installed in the lower editions of VS, however it's frely avaiable in the upper ones. No idea if that's "free enough" for you. Have a look to those questions and articles about it:

https://stackoverflow.com/questions/21847835/how-do-install-microsoft-fakes-unit-test-isolation-on-vs-2013-professional-edi

http://www.dotnetcurry.com/showarticle.aspx?ID=963

However, in my opinion, the very need of such "elevated" features shows a flawed design in the code under test, that precludes isolated unit testing. Code directly calling static methods will always have such problems, and the typical solution is to use dependency injection instead, decoupling static calls behind an interface and injecting and mocking it afterwards (but a discussion of that is not relevant to this site, StackOverflow is better suited for it). For those situations, I use both Moq and NSubstitute, both of them are much simpler proxy-based mock frameworks.

4

You could use common mocking frameworks like FakeItEasy or Moq and solve some of your "advanced" scenarios with tools like Ionad.Fody and EnableFaking.Fody. These modify the compiled IL code (weaving) so that you can mock it. However there's limitations and you most likely won't be able to address all of your advanced needs.

3

A completely free possibility is Prig, which is even open-source. It may be a bit less user-friendly than the commercial alternatives, but seems to work quite well. Note that if the signature of the method doesn't match one of the pre-defined delegates it will silently fail to generate the method to mock it - you have to manually define the missing delegate type as described here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.