共用方式為


在 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 檔案。 因此,它會以一般 XML 標頭開頭(行 1)。

行 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 標籤會辨識為元數據(屬性)。 Properties 下的所有單一層級 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 測試檔案只能封裝單一測試,因此修改測試行為的其他測試的 TAEF 元數據,例如 ExecutionGroup,也將無法運作。
  • 由於AXE架構,AXE 只能執行提升許可權的進程。 因此,如您在上述 TAEF AXE 測試的屬性中看到,每個 TAEF AXE 測試都已套用 Property[RunAs] = 提升權限

具有運行時間參數的AXE測試檔案

TAEF AXE 測試也支援運行時間參數。 若要搭配 AXE 測試使用 TAEF 的運行時間參數,必須將傳遞至可執行程式的參數名稱定義在 AXE 測試檔案中。

本文件無法詳細描述所有可能的AXE manifest參數功能。 如需該資訊,請參閱 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。 它由與上述說明的清單中的 描述 區段完全相同的強制性 Description 區段組成。 然後您會看到定義參數數據類型 Type 標記。 (如需所有支持的數據類型,請參閱 AXE 評估檔。)

選擇性 CommandLineFormat 一節說明評估命令行的評估參數格式。 這個 XML 節點必須包含有效的 .NET 格式字串的非空白字串。 評估參數值會是唯一傳遞至格式器的物件。 這表示格式字串必須包含且只包含一個索引為零的複合格式項目。 一些範例包括:-input {0}、/affinity:0x{0、X}或 -InputFile=“{0}” 。

下一個參數是在第 37 - 48 行 定義,而且是必要參數。 其定義與上一個參數的唯一差異是可選的 必要 標記。 此標記表示 AXE 預期使用者在 AXE 測試執行期間傳遞此參數。 如果省略此參數,則會使用參數數據類型的預設值(例如 INT 的零、String 的空字串等等)。

最後,範例中的最後一個參數會指定選擇性 DefaultValue 標記,其描述參數的預設值。 如果這個節點是空白的,則會使用參數數據類型的預設值做為預設值。 上述範例使用 「%AssessmentResultsPath%」,這是AXE 在評估開始執行時所設定的環境變數。 同樣地,如需所有支援的 AXE 環境變數,請參閱 AXE 評估檔。

參數會以其定義的反向順序傳遞至可執行檔 - 最後一個檔案中定義的參數會先傳遞至可執行檔。

您執行 TAEF AXE 執行時參數 測試,就像執行其他所有使用執行時參數的 TAEF 測試一樣(使用 /p 命令列選項):

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.dllMicrosoft.Assessment.dll 複製到 TAEF 或 TAEF AXE 測試目錄。