Use Moq to make mocking easier in Unit-Tests #1117
Replies: 4 comments 1 reply
-
My opinion of Moq varies quite a bit. I have used it extensively in other projects and it has been great but later on I find it's usage results in more difficult to follow code/tests. While on the topic of mocking I would like to advocate for making our current mocks more descriptive so rather than writing something like: var mockConverter = new MockValueConverter(value => true); We could modify it to something like: var mockConverter = MockValueConverter.ThatReturns(true, for: value); You don't easily get this readability from Moq but you could wrap it underneath. Also I believe a number of our mocks have been lifted from the .NET MAUI repo. That isn't me saying I'm against it but I don't see a big enough reason to do it. I am happy to be persuaded otherwise though 🙂 |
Beta Was this translation helpful? Give feedback.
-
I prefer NSubstitute. It has a much cleaner syntax. However, we decided to use Fake implementation to test without 3rd party libraries |
Beta Was this translation helpful? Give feedback.
-
I understand your decision. I have 2 question then: To test a class like
I can live with the fact that we do not add this library, as it would increase package size as well. But I would love to know how to contribute to the unit-tests in these instances in a proper way. |
Beta Was this translation helpful? Give feedback.
-
Closed as answered |
Beta Was this translation helpful? Give feedback.
-
Hi,
I would love to know if
Moq
(https://github.com/moq/moq4) mocking library has ever been considered to be added to theMaui.CommunityToolkit
?If not, this would be the discussion section for this.
The problem: At the moment we have to create extra classes just to use them as a Mock, as far as my understanding goes.
All opinions welcome of course, I am willing to do some PR's for Unit tests and want to make it easier for myself and others if possible.
Beta Was this translation helpful? Give feedback.
All reactions