IHostedTest Interface

A test type that implements the IHostedTest interface or inherits from a class that implements the IHostedTest interface can be hosted by a host adapter. Custom test types are usually derived from the TestElement class, and the TestElement class implements the IHostedTest interface. Consequently, any test type that derives from TestElement can be hosted by a host adapter.

Namespace:  Microsoft.VisualStudio.TestTools.Common
Assembly:  Microsoft.VisualStudio.QualityTools.Common (in Microsoft.VisualStudio.QualityTools.Common.dll)

public interface IHostedTest

The IHostedTest type exposes the following members.

  NameDescription
Public propertyHostTypeThe IHostedTest.HostType string identifies a host. Testers can use this string in the HostType attribute on a custom test to specify a host in which to run that test.
Top

If your custom test type does not derive from TestElement, your tests can be hosted by a host adapter if you do either of the following:

  • Code your test type to implement IHostedTest.

  • Do not have your test type implement IHostedTest. In this case, your test type can still be hosted if you configure hosting rules in the registry. For more information, see Configuring Host Adapters and Test Types.

The property window has two properties that TestElement provides: Host Type and Host Data. These properties are available for any test type that derives from TestElement.

For the complete code of the following example, see the MyTest.cs file in the test extensibility sample in the Visual Studio SDK.

using Microsoft.VisualStudio.TestTools.Common;
using Microsoft.VisualStudio.TestTools.Vsip;

class MyTest : TestElement 
{
    // TestElement - specific members.
    // ...

    // Copy constructor: copy m_hostType.
    public MyTest(MyTest copy)
        : base(copy)
    {
        // TestElement - specific data.
        // …

        m_hostType = copy.m_hostType;
    }

    // ITestElement.Clone is required by test case management.
    // Call copy constructor which copies m_hostType, 
    // so that cloned test has the same m_hostType as original test.
    public override object Clone()
    {
        return new MyTest(this);
    }

    // Persisted host type associated with the test.
    [PersistenceElementName("HostType")]
    private string m_hostType;
}

Community Additions

ADD
Show: