BlackWaspTM

This web site uses cookies. By using the site you accept the cookie policy.This message is for compliance with the UK ICO law.

<< Previous | 1 | 2 | 3 | 4 | Next >> |
Generate Return Values Using Lambdas in MoqGenerate Return Values Using Lambdas in Moq
Mock objects and stubs created using the Moq framework are generally used to inject dependencies with expectations that define fixed results. For more complex scenarios, lambda expressions can be used to generate results based on provided arguments.
Mocking Internal Types with MoqMocking Internal Types with Moq
To perform successful unit testing classes should be isolated from their dependencies. When the dependencies are internal and tests are in a separate project, this can be achieved using a combination of Moq and C# friend assemblies.
Mocking Property Expectations with MoqMocking Property Expectations with Moq
Moq provides similar capabilities when mocking properties of classes or interfaces as when mocking methods. Although the same verification and expectation set up methods can be used in some circumstances, there are additional options for properties.
Mocking Events with MoqMocking Events with Moq
When a class has dependencies that raise events, the reaction to those events should be unit tested. To do so, the dependencies should be isolated from the code under test with the use of test doubles. One option is to use Moq to create mock objects.
Unit Testing Raised EventsUnit Testing Raised Events
Many classes use events to allow messages to be passed to other classes in a loosely coupled manner. When creating unit tests for classes that use events, the raising of those events and the arguments generated should be verified.
Verifying the Number of Calls to a Mocked MethodVerifying the Number of Calls to a Mocked Method
The use of mock objects within unit tests allows you to verify that the correct calls to dependencies are made when a test is run. Rather than simply checking that a call is made, it is often essential to check how many times a method was executed.
NUnit Expected ExceptionsNUnit Expected Exceptions
When code enters an unexpected state, or when a member is called with invalid parameters, it is usual to throw an exception. When writing unit tests, the test code should ensure that the correct exceptions are thrown.
Queuing Moq Return ValuesQueuing Moq Return Values
Some testing scenarios require that a dependency's methods are called repeatedly. When the dependency is mocked using the Moq framework, these calls can be configured with expectations to return different results each time.
NUnit Timed TestsNUnit Timed Tests
Sometimes, when performing automated testing, it is necessary to ensure that a test is completed within a given period of time. NUnit helps this type of testing with attributes that fail tests that run for longer than a specified duration.
Using MocksUsing Mocks
The fourteenth part of the Automated Unit Testing tutorial concludes the description of isolating a class from its dependencies using test doubles. This article explains how mock objects can be used to fake large classes and to test expected behaviour.
<< Previous | 1 | 2 | 3 | 4 | Next >> |