Share via


如何新增測試元數據

針對 Windows 8,Windows 驅動程式套件 (WDK) 會使用 Test Authoring and Execution Framework (TAEF) 來建立測試內容。 TAEF 測試是實作為動態連結庫的物件, (DLL) 包含多個方法,其中每個方法都會對應至特定的測試案例。 TAEF 物件會將相關方法結合成一組測試。 每個測試都有一組描述測試的元數據。 為了改善測試可移植性和封裝,TAEF 會將測試元數據儲存在測試物件本身內。 當您使用驅動程式測試範本建立自己的驅動程式測試時,您需要新增此元數據,讓驅動程式測試可供使用,而且可以使用 Visual Studio 進行部署。

先決條件

新增測試元數據屬性

  1. 將必要的測試屬性元數據新增至測試的來源檔案。

  2. 例如,如果您使用驅動程式測試範本來建立您的 SurpriseRemove 測試版本,則會新增下列元數據。 編輯測試描述、顯示名稱、類別和結果檔案屬性。

    C++
    // Declare the test class method DoSurpriseRemove - the main test method within this class
        BEGIN_TEST_METHOD(DoSurpriseRemove)
        // Required properties for driver tests
        TEST_METHOD_PROPERTY(L"Kits.Drivers", L"TRUE")
        TEST_METHOD_PROPERTY(L"Kits.Parameter", L"DQ")
        TEST_METHOD_PROPERTY(L"Kits.Parameter.DQ.Description", L"A WDTF SDEL query that is used to identify the target device(s) - https://go.microsoft.com/fwlink/p/?linkid=232678")
        TEST_METHOD_PROPERTY(L"Kits.Parameter.DQ.Default", L"INF::OriginalInfFileName='%InfFileName%'")  
        TEST_METHOD_PROPERTY(L"RebootPossible", L"true")
        // TODO: Required properties to be customized to match your test requirements
        TEST_METHOD_PROPERTY(L"Description", L"Plug and Play Surprise Remove Generated Template")
        TEST_METHOD_PROPERTY(L"Kits.DisplayName", L"My Plug and Play Surprise Remove Test") 
        TEST_METHOD_PROPERTY(L"Kits.Category", L"My Test Category")
        // Optional properties for driver tests
        TEST_METHOD_PROPERTY(L"Kits.Drivers.ResultFile", L"TestTextLog.log")
        // TODO: (see Windows Driver Kit documentation for additional optional properties)
        END_TEST_METHOD()
    C#
    //
        // DoSurpriseRemove is a test method as identified by the [TestMethod] tag. 
        // More methods can be added by following this basic pattern.
        // The name of the function defines the name of the test.
        //
        [TestMethod]
        // Required properties (see Windows Driver Kit documentation for more information):
        [TestProperty("Kits.Drivers", "TRUE")]
        [TestProperty("Kits.Parameter", "DQ")]
        [TestProperty("Kits.Parameter.DQ.Description", "A WDTF SDEL query that is used to identify the target device(s) - https://go.microsoft.com/fwlink/p/?linkid=232678")]
        [TestProperty("Kits.Parameter.DQ.Default", "INF::OriginalInfFileName='%InfFileName%'")]
        // TODO: Required properties to be customized to match your test requirements.
        [TestProperty("Description", "Plug and Play Surprise Remove Generated Template")]
        [TestProperty("Kits.DisplayName", "My Plug and Play Surprise Remove Test")]
        [TestProperty("Kits.Category", "My Test Category")]
        [TestProperty("RebootPossible", "true")]
        // Optional properties (see Windows Driver Kit documentation for additional optional properties):
        [TestProperty("Kits.Drivers.ResultFile", "TestTextLog.log")]

    Windows 腳本元件 (.wsc)

    <!-- Define a test method with metadata: -->
        <method name="PlugAndPlaySurpriseRemoveTest">
        <!-- Required properties for ERT-->
        <TestMethodProperty name="Kits.Drivers" value="TRUE"/>
        <TestMethodProperty name="Kits.Parameter" value="DQ"/>
        <TestMethodProperty name="Kits.Parameter.DQ.Description" value="A WDTF SDEL query that is used to identify the target device(s) - https://go.microsoft.com/fwlink/p/?linkid=232678"/>
        <TestMethodProperty name="Kits.Parameter.DQ.Default" value="INF::OriginalInfFileName='%InfFileName%'"/>
        <TestMethodProperty name="RebootPossible" value="true" />
        <!-- TODO: Properties to be customized to match your test requirements -->
        <TestMethodProperty name="Description" value="Plug and Play Surprise Remove Generated Template"/>
        <TestMethodProperty name="Kits.DisplayName" value="My Plug and Play Surprise Remove Test"/>
        <TestMethodProperty name="Kits.Category" value="My Test Category"/>
        <!-- Optional properties for ERT-->
        <TestMethodProperty name="Kits.Drivers.ResultFile" value="TestTextLog.log"/>
        <!-- (see Windows Driver Kit documentation for additional optional properties) -->
        </method>
  3. 下表描述測試屬性屬性。 當您編輯或新增測試的元數據時,請使用指導方針的範例。

    描述
    測試用途的簡短描述。

    [Script] 
      < TestProperty name="Description" value= "This test cycles the system through various sleep states and performs IO on devices before and after each sleep state cycle"/>
    

    C++
    [C++]

    TEST_METHOD_PROPERTY(L"Description", L"Plug and Play Surprise Remove Generated Template")

    DisplayName
    測試的名稱,如驅動程序測試所示。

    [腳本]

    < TestProperty name="Kits.DisplayName" value="Sleep with IO Before and After"/>

    C++
     [C++]

    TEST_METHOD_PROPERTY(L"Kits.DisplayName", L"My Plug and Play Surprise Remove Test")

    Kits.Parameter
    方法呼叫的標準參數。 測試可以有多個參數。

    [腳本]

    <ModuleProperty name="Kits.Parameter" value="TM"/>

    C++
    [C++]

    TEST_METHOD_PROPERTY(L"Kits.Parameter", L"DQ")

    Kits.Parameter。<ParameterName>。描述
    參數的描述。

    [腳本]

    < TestProperty name="Kits.Parameter.TM.Description" value="Test mode parameter: Logo or Simple"/>

    C++
     [C++]

    TEST_METHOD_PROPERTY(L"Kits.Parameter.DQ.Description", L"A WDTF SDEL query that is used to identify the target device(s)")

    Kits.Parameter。<ParameterName>。預設
    參數的預設值。

    [腳本]

    < TestProperty name="Kits.Parameter.TM.Default" value="Logo"/>

    C++
    [C++]

    TEST_METHOD_PROPERTY(L"Kits.Parameter.DQ.Default", L"INF::OriginalInfFileName='%InfFileName%'")

    Kits.Drivers
    此屬性會標示要包含在 WDK 中的測試。

    [腳本]

    < TestProperty name="Kits.Drivers" value=""/>

    C++
    [C++]

    TEST_METHOD_PROPERTY(L"Kits.Drivers", L"TRUE")

    Kits.Category
    描述測試的類別。

     [腳本]

    < TestProperty name="Kits.Category" value="Logo\Device Fundamentals"/>

    C++
     [C++]

    TEST_METHOD_PROPERTY(L"Kits.Category", L"My Test Category")

    Deploymentitem
    將檔案和/或資料夾識別為測試相依性。 這些可能包含執行測試所需的任何資源。 如需使用此元數據的詳細資訊,請參閱 DeploymentItem 元數據