Question: How do I mock objects in the new coreclr world?

Question

How do I mock objects in the new coreclr world?

Answers 2
Added at 2016-01-11 11:01
Tags
Question

I have always been using Moq for mocking external dependencies while unit testing. Now that I am trying to make my code completely cross platform, I want to make my unit tests run on linux too and so I am targeting my project coreclr50.

The issue is I can't seem to find any mocking libraries that would enable me to mock on coreclr. LightMock.vNext has attempted to do it, but it requires creating mock classes manually which is not convenient.

I wonder how are people unit testing their MVC 6 controllers!

Answers to

How do I mock objects in the new coreclr world?

nr: #1 dodano: 2016-01-11 20:01

The ASP.NET team seems to be using Moq https://github.com/aspnet/Mvc/blob/dev/test/Microsoft.AspNet.Mvc.Core.Test/project.json:

 "dnxcore50": {
  "dependencies": {
    "moq.netcore": "4.4.0-beta8"
  }
}
nr: #2 dodano: 2016-01-12 12:01

NSubstitute is a great mocking framework. As far as I can see they don't directly support coreclr yet, but they have a pull request on GitHub for that:

https://github.com/nsubstitute/NSubstitute/pull/197

So you can try to do it yourself or wait a bit. Moq was a good framework, but as far as I remember it's not maintained for a long time now. NSubstitute has nicer syntax as well (at least IMHO :)

Source Show
◀ Wstecz