Verifies that a contract has been satisfied.

Namespace:  MbUnit.Framework.ContractVerifiers
Assembly:  MbUnit (in MbUnit.dll) Version: 3.3.0.0 (3.3.459.0)

Syntax

C#
public class VerifyContractAttribute : PatternAttribute
Visual Basic (Declaration)
Public Class VerifyContractAttribute _
	Inherits PatternAttribute

Remarks

This attribute is applied to a field of type IContract to that describes a contract to be verified. Each contract object is like a reusable test suite that can be customized by providing constructor parameters or by setting properties. MbUnit includes several out-of-the-box contract verifier implementations that capture common testing patterns for verifying the implementation of equivalence relations, exceptions, collections, accessors and other code.

Contract verifiers can be incorporated into test fixtures in two ways.

  • Contract stored in a readonly instance field. The contract verifier tests will be generated dynamically at test execution time similarly to a DynamicTestFactoryAttribute. This mechanism is compatible with data-driven test fixtures (such as generic test fixtures or fixtures with constructor parameters) but the user will be unable to individually view and select each test in the test runner before running them.
  • Contract stored in a readonly static instance field. The contract verifier tests will be generated statically at test exploration time similarly to a StaticTestFactoryAttribute. This mechanism can only be used in non-generic test fixtures but the user will be able to individually view and select each test in the test runner before running them.

Examples

CopyC#
[TestFixture]
public class MyExceptionTests
{
    // "dynamic" contract verifier (similar to a DynamicTestFactory)
    [VerifyContract]
    public readonly IContract Contract1 = new ExceptionContract<MyException>();

    // "static" contract verifier (similar to a StaticTestFactory)
    [VerifyContract]
    public readonly static IContract Contract2 = new ListContract<MyList<int>, int>();
}

Inheritance Hierarchy

System..::.Object
  System..::.Attribute
    Gallio.Framework.Pattern..::.PatternAttribute
      MbUnit.Framework.ContractVerifiers..::.VerifyContractAttribute

See Also