Share via


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)

Syntax

'Declaration
Public Interface IHostedTest
'Usage
Dim instance As IHostedTest
public interface IHostedTest
public interface class IHostedTest
public interface IHostedTest

Remarks

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.

Examples

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;
}

See Also

Reference

IHostedTest Members

Microsoft.VisualStudio.TestTools.Common Namespace