使用 AXE 创作测试

TAEF 支持创作使用评估执行引擎 (AXE) 执行的测试。

TAEF 中的 AXE 支持使 TAEF 能够执行 AXE 评估清单。 它主要用于将旧版测试(作为命令行 EXE 编写)包装到基于 XML 的 AXE 评估清单中。 这样,这些旧版测试即可通过 TAEF 执行,而无需将测试重写为 TAEF 本机、托管或脚本测试。

AXE 测试布局

尽管常规 TAEF 测试文件可以包含多个测试类和测试,但 TAEF AXE 测试 (由 AXE 评估清单定义的测试) 只能包含一个测试,因为清单包装了单个可执行文件。 因此,在 TAEF AXE 测试文件中查看测试时,始终会看到测试文件 (你正在) 查看的 AXE 评估清单,其中包含单个测试类和单个测试:

te Examples\AXE.Basic.Examples.manifest /list
Test Authoring and Execution Framework v2.7 Build 6.2.7918.0 (1320) For x64


        D:\enddev2.binaries.amd64chk\Test\CuE\TestExecution\Examples\AXE.Basic.Examples.manifest
            Basic
                Basic::Basic

AXE 测试也不支持任何设置或清理方法。

创作 AXE 测试

对于 AXE 测试,TAEF 使用 AXE 评估清单文件格式。

最小 AXE 测试文件

AXE 评估清单架构旨在支持对复杂方案的复杂评估进行非常丰富的描述。 但是,清单也可以非常简单,因为必需的节点非常少。 以下示例显示了包含所有必需标记的最小清单。

1<?xml version="1.0" encoding="utf-8"?>
2<AxeAssessmentManifest xmlns="http://www.microsoft.com/axe/assessment/manifest">
3  <VersionedId>
4    <Guid>{ABCBFDE6-D731-4030-9049-E7CAAB6A6EEE}</Guid>
5    <Version>
6      <Major>1</Major>
7      <Minor>0</Minor>
8      <Build>0</Build>
9      <Revision>0</Revision>
10    </Version>
11  </VersionedId>
12  <MinimumAxeVersionRequired>
13    <Version>
14      <Major>1</Major>
15      <Minor>0</Minor>
16      <Build>1</Build>
17      <Revision>0</Revision>
18    </Version>
19  </MinimumAxeVersionRequired>
20  <Description>
21    <ProgrammaticName>Basic</ProgrammaticName>
22    <DisplayName>Basic Examples</DisplayName>
23    <ToolTip>Sample Basic Examples Assessment Tooltip</ToolTip>
24  </Description>
25  <Meta>
26    <ExitValueMeaning> <ZeroIsSuccess/> </ExitValueMeaning>
27  </Meta>
28  <Execution>
29    <CreateProcess>
30      <ApplicationName>AssessmentSample.exe</ApplicationName>
31    </CreateProcess>
32  </Execution>
33</AxeAssessmentManifest>

AXE 测试评估文件是 XML 文件。 因此,它从第 1 行) (普通 XML 标头开始。

第 2 行 将 XML 文件标识为 AXE 清单。

第 3 行 - 第 10 行 为测试提供了可用于唯一标识测试的标识和版本。

第 12 行 - 19 指定解释此清单和运行测试所需的最低版本的 AXE。

第 20 - 24 行 为测试提供人类可读的名称和简短的工具提示说明。 请注意,查看测试属性时,测试类名称和测试名称将对应于 ProgrammaticName 元素值:

D:\enddev2.binaries.amd64chk\WexTest\CuE\TestExecution>te Examples\AXE.Basic.Examples.manifest /list
Test Authoring and Execution Framework v2.7 Build 6.2.7918.0 (1320) For x64


        D:\enddev2.binaries.amd64chk\Test\CuE\TestExecution\Examples\AXE.Basic.Examples.manifest
            Basic
                Basic::Basic

人类可读名称分配给 DisplayName 属性。 此分配是由于内部 TAEF 体系结构和设计造成的。

Te Examples\AXE.Basic.Examples.manifest /listproperties
Test Authoring and Execution Framework v2.7 Build 6.2.7918.0 (1320) For x64


        D:\enddev2.binaries.amd64chk\Test\CuE\TestExecution\Examples\AXE.Basic.Examples.manifest
                Property[TaefTestType] =  AxeAssessment

            Basic
                Basic::Basic
                        Property[DisplayName] =  Basic Examples
                        Property[ProgrammaticName] =  Basic
                        Property[RunAs] =  Elevated
                        Property[ToolTip] =  Sample Basic Examples Assessment Tooltip

此评估包装名为 AssessmentSample.exe的简单现有测试 EXE。 AssessmentSample.exe 使用通用约定返回进程退出代码,表示成功,返回非零值表示失败。

第 25 - 27 行 告知 AXE 和 TAEF,退出值零表示测试成功,任何其他值表示失败。

最后, 第 28 - 32 行 指示 AXE 使用 Win32 API CreateProcess () 执行 AssessmentSample.exe

在 AXE 测试文件中使用元数据

与任何其他 TAEF 测试一样,还可以将元数据应用于 TAEF AXE 测试。 请考虑下面所示的示例。

1<?xml version="1.0" encoding="utf-8"?>
2<AxeAssessmentManifest xmlns="http://www.microsoft.com/axe/assessment/manifest">
3  <VersionedId>
4    <Guid>{F310F3F6-F786-4118-8A18-BC020C7D2521}</Guid>
5    <Version>
6      <Major>1</Major>
7      <Minor>0</Minor>
8      <Build>0</Build>
9      <Revision>0</Revision>
10    </Version>
11  </VersionedId>
12  <MinimumAxeVersionRequired>
13    <Version>
14      <Major>1</Major>
15      <Minor>0</Minor>
16      <Build>1</Build>
17      <Revision>0</Revision>
18    </Version>
19  </MinimumAxeVersionRequired>
20  <Description>
21    <ProgrammaticName>CustomMetadataExamples</ProgrammaticName>
22    <DisplayName>Custom Metadata Examples</DisplayName>
23    <ToolTip>Sample Custom Metadata Examples Assessment Tooltip</ToolTip>
24  </Description>
25  <Properties>
26    <Owner>Someone</Owner>
27    <Priority>1</Priority>
28    <Parallel>false</Parallel>
29  </Properties>
30  <Meta>
31    <ExitValueMeaning> <ZeroIsSuccess/> </ExitValueMeaning>
32  </Meta>
33  <Execution>
34    <CreateProcess>
35      <ApplicationName>AssessmentSample.exe</ApplicationName>
36    </CreateProcess>
37  </Execution>
38</AxeAssessmentManifest>

第 25 - 29 行 演示了如何将 TAEF 标准和自定义元数据应用于 AXE 测试。 在 AxeAssessmentManifest XML 节点下是 一个 Properties 节点。 “属性”节点下的单个级别 XML 标记被识别为元数据 (属性) 。 “属性”下的所有单级 XML 标记都解释为属性名称,其文本值解释为属性值。 在上面的示例中, 所有者 被解释为属性名称, 将 Someone 解释为属性值。 这些元素中没有文本的 XML 标记被解释为其值等于空字符串的元素, (例如 SimpleTagWithNoText</>) 。 “属性”下的多级 XML 标记将被忽略 (例如,多级标记,例如

<VerifyOSVersion>
    <Major>6</Major>
    <Minor>0</Minor>
    <Build>0</Build>
</VerifyOSVersion>

将忽略) 。 与任何其他 TAEF 测试类似,可以使用 /listProperties 选项来显示 TAEF 元数据:

te Examples\AXE.CustomMetadata.Examples.manifest /listProperties
Test Authoring and Execution Framework v2.7 Build 6.2.7918.0 (1320) For x64

        D:\enddev2.binaries.amd64chk\Test\CuE\TestExecution\Examples\AXE.CustomMetadata.Examples.manifest
                Property[TaefTestType] =  AxeAssessment

            CustomMetadataExamples
                CustomMetadataExamples::CustomMetadataExamples
                        Property[DisplayName] =  Custom Metadata Examples
                        Property[Owner] =  Someone
                        Property[Parallel] =  false
                        Property[Priority] =  1
                        Property[ProgrammaticName] =  CustomMetadataExamples
                        Property[RunAs] =  Elevated
                        Property[ToolTip] =  Sample Custom Metadata Examples Assessment Tooltip


AXE 测试元数据支持限制

注意

并非所有 TAEF 标准测试元数据都可用于 TAEF AXE 测试。

  • 旨在修改进程执行环境的所有元数据(如 ActivationContextThreadingModel)都不适用于 AXE 测试。 AXE 不使用 TAEF 的进程来执行测试,但会创建一个新进程,在其中运行由 AXE 测试文件 (AXE 评估清单) 指定的可执行程序。 出于同样的原因,数据驱动的 TAEF 测试 (DataSource 属性) 也不适用于 AXE TAEF 测试。
  • 同样,由于 TAEF AXE 测试文件只能封装单个测试,因此修改针对其他测试(如 ExecutionGroup)的测试行为的 TAEF 元数据也将不起作用。
  • 由于 AXE 体系结构,AXE 只能运行提升的进程。 因此,从上述 TAEF AXE 测试的属性中看到,每个 TAEF AXE 测试都应用了 Property[RunAs] = Elevated

具有运行时参数的 AXE 测试文件

TAEF AXE 测试还支持运行时参数。 若要将 TAEF 的运行时参数用于 AXE 测试,需要在 AXE 测试文件中定义要传递给可执行程序的参数名称。

本文档不介绍如何在所有详细信息中介绍所有可能的 AXE 清单参数功能。 有关该信息,请参阅 AXE 评估文档。 本文档仅介绍最常见和最有用的参数应用程序。

以下示例显示了更复杂的 AXE 评估清单。

1<?xml version="1.0" encoding="utf-8"?>
2<AxeAssessmentManifest xmlns="http://www.microsoft.com/axe/assessment/manifest">
3  <VersionedId>
4    <Guid>{B63B2FFF-EDEB-41FB-92EA-529CE4A46D20}</Guid>
5    <Version>
6      <Major>1</Major>
7      <Minor>0</Minor>
8      <Build>0</Build>
9      <Revision>0</Revision>
10    </Version>
11  </VersionedId>
12  <MinimumAxeVersionRequired>
13    <Version>
14      <Major>1</Major>
15      <Minor>0</Minor>
16      <Build>1</Build>
17      <Revision>0</Revision>
18    </Version>
19  </MinimumAxeVersionRequired>
20  <Description>
21    <ProgrammaticName>ExplicitRuntimeParameters</ProgrammaticName>
22    <DisplayName>Explicit Runtime Parameters</DisplayName>
23    <ToolTip>Sample Explicit Runtime Parameters Assessment Tooltip</ToolTip>
24  </Description>
25  <ParameterDefinitions>
26    <ParameterDefinition>
27      <Description>
28        <ProgrammaticName>SimpleParameter</ProgrammaticName>
29        <DisplayName>Simple parameter</DisplayName>
30        <ToolTip>The is an example of a simple parameter.</ToolTip>
31      </Description>
32      <Type>
33        <String></String>
34      </Type>
35      <CommandLineFormat>{0}</CommandLineFormat>
36    </ParameterDefinition>
37    <ParameterDefinition>
38      <Description>
39        <ProgrammaticName>RequiredParameterWithoutDefaultValue</ProgrammaticName>
40        <DisplayName>Required parameter without a default value.</DisplayName>
41        <ToolTip>The is an example of a required parameter Without a default value.</ToolTip>
42      </Description>
43      <Required>True</Required>
44      <Type>
45        <Int></Int>
46      </Type>
47      <CommandLineFormat>{0}</CommandLineFormat>
48    </ParameterDefinition>
49    <ParameterDefinition>
50      <Description>
51        <ProgrammaticName>RequiredParameterWithDefaultValue</ProgrammaticName>
52        <DisplayName>Required parameter with a default value</DisplayName>
53        <ToolTip>The is an example of a required parameter With a default value.</ToolTip>
54      </Description>
55      <Required></Required>
56      <DefaultValue>"%AssessmentResultsPath%"</DefaultValue>
57      <Type>
58        <String></String>
59      </Type>
60      <CommandLineFormat>/RequiredParameterWithDefaultValue={0}</CommandLineFormat>
61    </ParameterDefinition>
62  </ParameterDefinitions>
63  <Meta>
64    <ExitValueMeaning> <ZeroIsSuccess/> </ExitValueMeaning>
65  </Meta>
66  <Execution>
67    <CreateProcess>
68      <ApplicationName>AssessmentSample.exe</ApplicationName>
69    </CreateProcess>
70  </Execution>
71</AxeAssessmentManifest>

第 25 - 62 行 是描述 TAEF 和 AXE 用于将数据传递到评估可执行文件的参数的参数定义。

最简单的参数定义位于 第 26 - 36 行。 它包含一个必需的 “说明 ”部分,该部分与清单的“ 说明 ”部分完全相同,如前所述。 然后,你将看到定义参数数据类型的 Type 标记。 (请参阅 AXE 评估文档,获取所有支持的数据类型。)

可选的 CommandLineFormat 部分介绍了如何为评估命令行设置评估参数的格式。 此 XML 节点必须包含一个非空字符串,该字符串是有效的 .NET 格式字符串。 评估参数值将是传递给格式化程序的唯一对象。 这意味着格式设置字符串必须包含一个且只有一个索引为零的复合格式设置项。 一些示例包括:-input {0}、/affinity:0x{0,X}或 -InputFile=“{0}”。

下一个参数在 行 37 - 48 上定义,是必需参数。 其定义与上一个参数的唯一区别是可选的 Required 标记。 此标记指示 AXE 要求用户在 AXE 测试执行期间传递此参数。 如果省略此参数,则参数数据类型的默认值将用于 (例如,零表示 INT,空字符串表示字符串等) 。

最后,示例中的最后一个参数指定可选的 DefaultValue 标记,用于描述参数的默认值。 如果此节点为空,则参数数据类型的默认值将用作默认值。 上面的示例使用“%AssessmentResultsPath%”,这是一个环境变量,在评估开始执行时由 AXE 设置。 同样,请参阅 AXE 评估文档,了解所有受支持的 AXE 环境变量。

参数按其定义的相反顺序传递给可执行文件 - 最后在文件中定义的参数首先传递给可执行文件。

使用 /p 命令行选项) ,将 TAEF AXE 运行时参数测试与使用运行时参数的任何其他 TAEF 测试一样执行 (:

te AXE.ExplicitRuntimeParameters.Examples.manifest /p:SimpleParameter=Test1 /p:RequiredParameterWithoutDefaultValue=10
Test Authoring and Execution Framework v2.7 Build 6.2.7918.0 (1320) For x64

ExplicitRuntimeParameters::ExplicitRuntimeParameters
AssessmentSample.exe is simple application for AXE assessment demo.
It just echoes the arguments passed to it to the console.

Parameters passed from the command line:
Argument[0]=AssessmentSample.exe
Argument[1]=10
Argument[2]=/RequiredParameterWithDefaultValue=C:\Results\JobResults_DEVRH_2011-0129_0250-12.394\0
Argument[3]=Test1

FileName: C:\Results\JobResults_DEVRH_2011-0129_0250-12.394\JobResults_DEVRH_2011-0129_0250-12.394.xml
Saved output file to: D:\enddev2.binaries.amd64chk\Test\CuE\TestExecution\WexLogFileOutput\
000001_~ExplicitRuntimeParameters_JobResults_DEVRH_2011-0129_0250-12.394.xml
EndGroup: ExplicitRuntimeParameters::ExplicitRuntimeParameters [Passed]

AXE 测试跨计算机执行

对于跨计算机执行方案,TAEF 会尝试确定需要与测试一起部署的测试依赖项,以便成功执行测试。 对于 AXE 测试文件,TAEF 会将包含 TAEF AXE 测试的同一文件夹中的所有文件复制到远程计算机执行。

当前不支持跨计算机对 Arm 平台执行 AXE 测试。

TAEF AXE 支持依赖项

AXE 不随 Windows 一起提供。 若要执行 AXE 测试,需要将 axecore.dll 复制并 Microsoft.Assessment.dll TAEF 或 TAEF AXE 测试目录。