IHostedTest 接口

对于实现 IHostedTest 接口或继承自实现 IHostedTest 接口的类的测试类型,可由主机适配器来承载。 自定义测试类型通常派生自 TestElement 类,而 TestElement 类实现 IHostedTest 接口, 因此所有派生自 TestElement 的测试类型都可由主机适配器承载。

命名空间:  Microsoft.VisualStudio.TestTools.Common
程序集:  Microsoft.VisualStudio.QualityTools.Common(在 Microsoft.VisualStudio.QualityTools.Common.dll 中)

语法

声明
Public Interface IHostedTest
public interface IHostedTest
public interface class IHostedTest
type IHostedTest =  interface end
public interface IHostedTest

IHostedTest 类型公开以下成员。

属性

  名称 说明
公共属性 HostType IHostedTest.HostType 字符串标识一台主机。执行自定义测试时,测试人员可以在 HostType 特性中使用此字符串来指定用于运行测试的主机。

页首

备注

如果不从 TestElement 派生自定义测试类型,则在执行下面的任一操作时测试可由主机适配器承载:

  • 编写测试类型以实现 IHostedTest。

  • 没有让您的测试类型实现 IHostedTest。 在这种情况下,如果在注册表中配置承载的规则,则仍可承载测试类型。 有关更多信息,请参见 Configuring Host Adapters and Test Types

属性窗口有 TestElement 提供的两个属性:主机类型和主机数据 这些属性可用于从 TestElement 派生的任何测试类型。

示例

有关下列示例的完整代码,请参见 Visual Studio SDK 中测试扩展性示例的 MyTest.cs 文件。

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

请参见

参考

Microsoft.VisualStudio.TestTools.Common 命名空间

其他资源

Configuring Host Adapters and Test Types