Mocking with Moq 4 and NUnit
Writing unit tests is hard when dependencies between classes make it tough to separate what's being tested from the rest of the system. Moq is a mocking library for .NET that makes it easy to create mock objects and make writing unit tests easier.
What you'll learn
Writing effective unit tests can be tricky when dependencies between classes make it hard to separate what's being tested from the rest of the system. In this course, Mocking with Moq 4 and NUnit, you will gain the ability to easily isolate parts of your codebase for testing purposes. First, you will learn how to substitute real dependencies for mock objects. Next, you will discover how to configure mocked methods, properties, exceptions, and events. Finally, you will explore how to create behavior-based tests and also how to create partial mocks from existing classes. When you’re finished with this course, you will have the skills and knowledge of mocking with Moq needed to create automated tests that use mock objects.
Table of contents
- Introduction 1m
- An Overview of Behavior Based Testing 5m
- Verifying a Method Where No Parameters Were Called 3m
- Verifying a Method Where a Parameter Was Called 3m
- Verifying a Method Was Called a Specific Number of Times 1m
- Verifying Property Setter and Getters Were Called 3m
- Verifying That No Unexpected Calls Were Made 1m
- Summary 2m
- Introduction 2m
- Understanding Strict Mocks 3m
- Throwing Exceptions from Mock Objects 3m
- Raising Events from Mock Objects 2m
- Understanding Partial Mocks 2m
- Creating Partial Mocks 3m
- Mocking Nondeterministic Code Such as DateTime.Now 2m
- Mocking Protected Members of Partial Mocks 4m
- An Alternative to Using Partial Mocks 2m
- Summary 2m