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


How do I mock objects in the new coreclr world?

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

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!

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

The ASP.NET team seems to be using Moq

 "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:

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