如何添加测试元数据

对于 Windows 8,Windows 驱动程序工具包 (WDK) 使用测试编写和执行框架 (TAEF) 来创建测试内容。TAEF 测试是作为动态链接库 (DLL) 实现的对象,它包含多种方法,其中每种方法都映射到特定的测试方案。TAEF 对象将相关方法组合到一组测试中。对于每个测试,都有一组元数据对其进行描述。为了改进测试的可移植性和封装,TAEF 将测试元数据存储在测试对象自身中。使用驱动程序测试模板创建自己的驱动程序测试时,你需要添加该元数据才能使用驱动程序测试,以及使用 Visual Studio 进行部署。

先决条件

添加测试元数据属性

  1. 向测试的源文件中添加所需的测试属性元数据。

  2. 例如,如果你使用驱动程序测试模板创建你的版本的 SurpriseRemove 测试,则添加以下元数据。编辑测试描述、显示名称、类别以及结果文件属性。

    // 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()
    
    //*************************************************
        // 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. 下表描述测试属性特性。当你编辑或添加测试的元数据时,将这些示例用作指南。

    • Description
      测试所执行操作的简短描述。

      [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++]
      
       TEST_METHOD_PROPERTY(L"Description", L"Plug and Play Surprise Remove Generated Template")
      
    • DisplayName
      测试在“驱动程序测试”中的显示名称。

      [Script] 
      
       < TestProperty name="Kits.DisplayName" value="Sleep with IO Before and After"/>
      
       [C++]
      
        TEST_METHOD_PROPERTY(L"Kits.DisplayName", L"My Plug and Play Surprise Remove Test") 
      
    • Kits.Parameter
      方法调用的标准参数。一个测试可以包含多个参数。

      [Script] 
      
      <ModuleProperty name="Kits.Parameter" value="TM"/>
      
      [C++]
      
      TEST_METHOD_PROPERTY(L"Kits.Parameter", L"DQ")
      
    • Kits.Parameter.<ParameterName>.Description
      参数的描述。

      [Script] 
      
      < TestProperty name="Kits.Parameter.TM.Description" value="Test mode parameter: Logo or Simple"/> 
      
      
      [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>.Default
      参数的默认值。

      [Script] 
      
      < TestProperty name="Kits.Parameter.TM.Default" value="Logo"/>
      
      [C++]
      
       TEST_METHOD_PROPERTY(L"Kits.Parameter.DQ.Default", L"INF::OriginalInfFileName='%InfFileName%'")  
      
    • Kits.Drivers
      该属性标记要包含在 WDK 中的测试。

      [Script] 
      
      < TestProperty name="Kits.Drivers" value=""/>
      
      [C++]
      
       TEST_METHOD_PROPERTY(L"Kits.Drivers", L"TRUE")
      
    • Kits.Category
      描述测试的类别。

       [Script] 
      
      < TestProperty name="Kits.Category" value="Logo\Device Fundamentals"/>
      
       [C++]
      
      TEST_METHOD_PROPERTY(L"Kits.Category", L"My Test Category")
      
    • Deploymentitem
      将文件和/或文件夹标识为测试依赖性。这些可能包含运行测试所需的所有资源。 有关使用该元数据的详细信息,请参阅 DeploymentItem 元数据

相关主题

如何使用驱动程序测试模板编写驱动程序测试