Creating unit tests with mocks
When implementing unit tests, it is important to isolate the units we are currently testing. By isolation, we are of course referring to the process of mocking the dependencies of the current subject under test. The mocks can be introduced in various ways, depending on the implementation of the Inversion of Control pattern. If the implementation involves constructor injection, we can mock our dependency interfaces in the first A of our test and pass it on to our target. Otherwise, frameworks such as NSubstitute can replace interfaces as well as concrete classes that are used by the subject.
Taking a look back at our view model and the unit test that was implemented, you might notice that we used the Moq framework ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access