VsTestClassBase Class

Provides a base class for test classes generated by Spec Explorer. Test classes generated from this class support the Visual Studio testing tools for unit tests.

Namespace: Microsoft.SpecExplorer.Runtime.Testing
Assembly: Microsoft.SpecExplorer.Runtime.VisualStudio (in Microsoft.SpecExplorer.Runtime.VisualStudio.dll)

Usage

'Usage

Syntax

'Declaration
public class VsTestClassBase : GeneratedTestClassBase, IDisposable

Example

The following Cord script and C# example shows an implementation of a custom test class, MyVsTestClassBase, that supports the Visual Studio unit testing environment and modifies the behavior of the VsTestClassBase class implementation.

In the Cord script, the Main configuration block sets some of the test generation switches, in particular, the TestClassBase switch, which indicates which base test class Spec Explorer should use in the generated test code.

In the C# code, the MyVsTestClassBase class extends the VsTestClassBase class. In its constructor, it sets the LogToFile property to true to generate a log file from the output from each test case and overrides the Assert and Assume methods to generate output before throwing an exception.

config Main 
{
    switch GeneratedTestPath = "..\\VsttEnvironment.TestSuite";
    switch GeneratedTestNamespace = "VsttEnvironment.TestSuite";

    switch TestClassBase = "VsttEnvironment.TestSuite.MyVsTestClassBase";

    // Define actions and set other switches here.
}
using Microsoft.SpecExplorer.Runtime.Testing;

namespace VsttEnvironment.TestSuite
{
    public class MyVsTestClassBase : VsTestClassBase
    {
        public MyVsTestClassBase()
        {
            this.LogToFile = true;
        }

        public override void Assert(bool condition, string description)
        {
            if (!condition)
            {
                Comment("Assert failed: " + description);
            }
            base.Assert(condition, description);
        }

        public override void Assume(bool condition, string description)
        {
            if (!condition)
            {
                Comment("Assume failed: " + description);
            }
            base.Assume(condition, description);
        }
    }
}

Remarks

During test code generation and on-the-fly testing, Spec Explorer extends the test class specified by the TestClassBase switch. The VsTestClassBase class provides a base test class that is suitable for the Visual Studio testing tools environment. In general, to create a base test class for a testing environment outside Visual Studio, define a custom base test class that extends the GeneratedTestClassBase class.

To extend the setup, logging, or reporting within the Visual Studio unit testing environment, extend this class and update the TestClassBase switch in the configuration file. The following list describes some common scenarios.

Inheritance Hierarchy

System.Object
   Microsoft.SpecExplorer.Runtime.Testing.GeneratedTestClassBase
    Microsoft.SpecExplorer.Runtime.Testing.VsTestClassBase

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Platforms

Development Platforms

Microsoft Windows 7, Microsoft Windows Vista, Microsoft Windows XP SP2 or later, Microsoft Windows Server 2008, Microsoft Windows Server 2003

Change History

See Also

Reference

VsTestClassBase Members
Microsoft.SpecExplorer.Runtime.Testing Namespace
IGeneratedTestClass Interface
IConfigurableGeneratedTestClass Interface
IBasicTestSite Interface
GeneratedTestClassBase Class
DefaultTestManager Class