共用方式為


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