The starting point for all unit tests is one of the UnitTest
abstract base classes:
public abstract class UnitTest<TTarget> ...
public abstract class UnitTest<TTarget, TReturnType> ...
The former class is for use with methods that do not have a return value, while the latter requires the method under test to return the specified type.
Which class you choose has an impact on the interface that must be used for defining actions and assertions.
classes have a Run
method that should be used for specifying the test:
public override void Run()
method requires a type argument which implements an IInitializerMarker
returns a fluent interface, allowing you to chain preconditions together:
method requires a type argument which matches the action specification. However, you can also pass in either an
or a Func<TTarget, TReturnType>
. Note that this will circumvent the English-language of the type argument style, but some actions are too simple to necessitate a new class definition.
method requires a type argument which matches the assertion specifcation. This also returns a fluent interface, much like
Notice that parameters have been supplied for the When
. This is also possible for
calls. Any parameters can be passed in here as the methods take
as their argument. These values will be passed to the constructor of the supplied type. Notice, however, that any type mismatches will not be caught at compile time. In fact, failing to supply the correct number of arguments will not be
caught at compile time.