Compartir a través de


TypeBinding Attribute

The TypeBinding attribute is assigned to a model type to establish a mapping between it and a type in the implementation (or adapter/harness).

Type bindings are used for translating rule-method parameters, which belong to model types, into action parameters, which belong to implementation types. When testing, a one-to-one mapping is established between instances returned by the implementation and model types instances appearing in assumptions derived from model exploration.

Type binding to a static class is not allowed.

Example

Here, the SimpleThread class in the model program is bound to the ComplexThread class in the implementation.

Model Program code snippet:

namespace SpecExplorer3
{
    /// <summary>
    /// A model class, bound to an sample class.
    /// </summary>
    [TypeBinding("SpecExplorer3.Sample.ComplexThread")]
    class SimpleThread
    {
           …

Implementation program code snippet:

namespace SpecExplorer3.Sample
{
    /// <summary>
    /// The implementation allows a thread to perform more than one step.
    /// Tests should still pass, because the model's behavior is a subset of the implementation's.
    /// </summary>
    public class ComplexThread
    {
          …

To create the solution containing this type binding, in Visual Studio select: New Project -> Visual C# -> Test -> Spec Explorer Model. When the Spec Explorer Model Wizard window appears, select Instance-Based Spec Explorer Model -> Next -> Finish. The code for the model program is in SimpleThread.cs, the code for the implementation is in ComplexThread.cs

See Also

Reference

TypeBindingAttribute

Concepts

Model Programs

Other Resources

Model Program Attributes