測試撰寫和執行架構 (TAEF) 提供一種機制,可根據您提供的中繼資料資訊,選擇性地執行或省略特定測試。 下一節將介紹如何將此選擇機制與 TE.exe一起使用的各種示例。
您可以從命令提示字元視窗執行 TE.exe。
TE <test_binaries> [/select:<selection criteria>]
本節說明 TE.exe /select:selection criteria 選項。 如需有關 TE.exe的詳細資訊,請參閱 TE.exe 命令選項。
選取準則會全域套用至命令提示字元中提及的所有測試二進位檔。 讓我們考慮兩個「test_binaries」:範例\CPP.SelectionCriteria1.Example.dll 和 範例\CPP.SelectionCriteria2.Example.dll 。 下列範例顯示在這些 test_binaries 中各個層級指定的中繼資料或屬性。 您也可以透過在命令提示字元視窗中指定 /listproperties 選項來取得此值。
CPP.SelectionCriteria1.Example.dll (Owner="C1", Priority=3)
class11 (Owner="C2")
method111(Priority=1)
method112 (BackwardsCompatibility="Windows 2000")
class12
method121
CPP.SelectionCriteria2.Example.dll (Owner="WEX")
class21 (Owner="C1", Priority=2, BackwardsCompatibility="Windows XP")
method211 (Owner="C2")
class22 (Owner="U3")
method221
換句話說,透過在每一個 test_binaries 上分別使用 /listproperties,您可以獲得:
F:\fsd1.binaries.x86chk\WexTest\C1\TestExecution>te Examples\CPP.SelectionCriteria1.Example.dll /listproperties
Test Authoring and Execution Framework v2.2 Build 6.1.7689.0 (release.091218-1251) for x86
F:\fsd1.binaries.x86chk\WexTest\C1\TestExecution\Examples\CPP.SelectionCriteria1.Example.dll
Property[Owner] = C1
Property[Priority] = 3
WEX::TestExecution::Examples::Class11
Property[Owner] = C2
WEX::TestExecution::Examples::Class11::Method111
Property[Priority] = 1
WEX::TestExecution::Examples::Class11::Method112
Property[BackwardsCompatibility] = Windows2000
WEX::TestExecution::Examples::Class12
WEX::TestExecution::Examples::Class12::Method121
以及:
F:\fsd1.binaries.x86chk\WexTest\C1\TestExecution>te Examples\CPP.SelectionCriteria2.Example.dll /listproperties
Test Authoring and Execution Framework v2.2 Build 6.1.7689.0 (release.091218-1251) for x86
F:\fsd1.binaries.x86chk\WexTest\C1\TestExecution\Examples\CPP.SelectionCriteria2.Example.dll
Property[Owner] = WEX
WEX::TestExecution::Examples::Class21
Property[BackwardsCompatibility] = Windows XP
Property[Owner] = C1
Property[Priority] = 2
WEX::TestExecution::Examples::Class21::Method211
Property[Owner] = C2
WEX::TestExecution::Examples::Class22
Property[Owner] = U3
WEX::TestExecution::Examples::Class22::Method221
此時請務必注意,test_binaries 會與其完整路徑一起列出,而在原生 test_binaries 中,類別名稱會列為 "<Namespace>::<ClassName>",在受控 test_binaries 中,類別名稱會列為 "<Namespace>.<ClassName>"。 同樣地,在原生測試二進位檔案的情況下,測試方法名稱會列為「<命名空間>::<類別名稱>::<TestMethodName>」,而在受控測試二進位檔案的情況下,則會列為「<命名空間>.<類別名稱>.<TestMethodName>」。
換句話說,任何名稱或函數的完全限定名稱都是保存在 te 中的名稱。 這是為了允許能夠唯一區分任何方法。 例如,如果兩個類別具有相同的方法名稱,則類別限定有助於唯一選取您感興趣的方法。 為此,選擇標準有助於僅運行在給定test_binaries中符合標準的測試。
在上面的範例中,例如在範例\Cpp.SelectionCriteria1.Example.dll中,您可以透過以下任一選擇準則選擇「方法111」:
Te.exe Examples\CPP.SelectionCriteria1.Example.dll /select:"@Name='WEX::TestExecution::Examples::Class11::Method111'"
Te.exe Examples\CPP.SelectionCriteria1.Example.dll /select:"@Name='*Class11::Method111'"
Te.exe Examples\CPP.SelectionCriteria1.Example.dll /select:"@Name='*Method111'"
您可以選擇執行所有「優先順序」標記小於 2 的測試,方法是:
Te.exe Examples\CPP.SelectionCriteria1.Example.dll Examples\CPP.SelectionCriteria2.Example.dll /select:"@Priority < 2"
這只會執行範例\CPP.SelectionCriteria1.Example.dll - 範例中的「class11::method111」。
如果您想要在 class11 下執行所有測試,您可以使用限定的 “Name” 屬性以及萬用字元比對來選擇它,如下所示:
Te.exe Examples\CPP.SelectionCriteria1.Example.dll Examples\CPP.SelectionCriteria2.Example.dll
/select:"@Name='*::class11::*'"
使用選取準則時,請記住以下幾點:
- “and”、“not” 和 “or” 是 保留 詞,不分 大小寫。
- 中繼資料屬性名稱和值不區分大小寫,例如範例中的 “C2” 會符合 “c2” 和 “C2”。 因此,如果您有一個函數具有元數據“屬性”,另一個函數具有“屬性”,並且選擇標準正在尋找“屬性”,則它將匹配這兩個函數。
- 選取查詢字串中的字串值應該包含在單引號中。 在選取查詢的字串值內,「?」是單一萬用字元,而「*」是 0 個或多個萬用字元。
- 在命令提示字元中使用引號時,當您要複製選取的查詢語句時,請注意智能引號的使用。 如果您從 Outlook 電子郵件複製選取查詢,可能會不小心出現智慧引號,而 TAEF 可能無法解析。 請改為輸入引號。
讓我們回顧一下化合物選擇標準的一些快速範例以及它們將執行的內容。
Te.exe Examples\CPP.SelectionCriteria1.Example.dll Examples\CPP.SelectionCriteria2.Example.dll \
/select:"@Owner='C2' AND @Priority=2"
將運行:
- 範例\CPP.SelectionCriteria2.Example.dll - class21::method211
Te.exe Examples\CPP.SelectionCriteria1.Example.dll Examples\CPP.SelectionCriteria2.Example.dll \
/select:"@Owner='C2' AND @Priority=3"
將運行:
- 範例\CPP.SelectionCriteria1.Example.dll - class11::method112
Te.exe Examples\CPP.SelectionCriteria1.Example.dll Examples\CPP.SelectionCriteria2.Example.dll \
/select:"@Owner='U3' oR @Priority=1"
將運行:
- 範例\CPP.SelectionCriteria1.Example.dll - class11::method111
- 範例\CPP.SelectionCriteria2.Example.dll - class22::method221
Te.exe Examples\CPP.SelectionCriteria1.Example.dll Examples\CPP.SelectionCriteria2.Example.dll \
/select:"not(@BackwardsCompatibility=*)"
會執行尚未指定 BackwardsCompatibility 值的所有測試。 (請參閱以下項目。
- 範例\CPP.SelectionCriteria1.Example.dll - class11::method111、class12::method121
- 範例\CPP.SelectionCriteria2.Example.dll - class22::method221
Te.exe Examples\CPP.SelectionCriteria1.Example.dll Examples\CPP.SelectionCriteria2.Example.dll \
/select:"@Owner='C*'"
將執行所有 Owner 值以 “C” 開頭的測試 (不區分大小寫)。 因此,上一個命令將在class21(即method21)下運行示例\CPP.SelectionCriteria1.Example.dll and all tests in Examples\CPP.SelectionCriteria2.Example.dll 中的所有測試
Te.exe Examples\CPP.SelectionCriteria1.Example.dll Examples\CPP.SelectionCriteria2.Example.dll \
/select:"not(@BackwardsCompatibility=*) OR (@Owner='C*' AND @BackwardsCompatibility='*XP*')"
會執行未指定 BackwardsCompatibility 的所有測試,或擁有者名稱以「C」開頭且 BackwardsCompatibility 值包含「XP」的所有測試。 請注意如何使用括號“(” 和 “)”來指定優先順序。
在此範例中,這會選擇性地執行:
- 範例\CPP.SelectionCriteria1.Example.dll - class11::method111、class12::method121、
- 範例\CPP.SelectionCriteria2.Example.dll - class21::method211、class22::method221
Te.exe Examples\CPP.SelectionCriteria1.Example.dll Examples\CPP.SelectionCriteria2.Example.dll /select:"@Owner='???'"
只會執行屬性擁有者值僅包含 3 個字元的測試。
在我們的範例中,這會符合「C」,並僅執行:
- 範例\CPP.SelectionCriteria1.Example.dll - class12::method121
Te.exe Examples\CPP.SelectionCriteria1.Example.dll Examples\CPP.SelectionCriteria2.Example.dll /select:"@Priority>=1"
備註
這是如何使用 “>=”、“<=”、“>” 和 “<” 的很好的範例,其中 propertyvalues 是浮點值。
在我們的範例中,這會執行除範例\CPP.SelectionCriteria2.Example.dll - class22::method221 之外的所有方法,其中未指定優先順序。 換句話說,這將執行:
- 範例\CPP.SelectionCriteria1.Example.dll - class11::method111、class11::method112、class12::method121
- 範例\CPP.SelectionCriteria2.Example.dll - class21::method211。
請注意,您可以將“/select”與其他命令選項(如“/list”、“/listproperties”等)結合使用。
智能報價
如果您將選擇條件從 Outlook 或 Word 文檔複製回命令提示符,您可能會在選擇條件中遇到智能引號。 您可以在 智慧型引號:用於計算機閱讀的文本的隱藏禍害 中找到有關智慧型引號的更多信息。
避免智慧引號沒有簡單的方法 - 最好的方法是在將選擇準則複製到命令提示字元並重新鍵入查詢的引號部分後,刪除選取準則中的所有「雙引號和單引號」。
有一個選項設置可以在 Outlook 中創建郵件時將其關閉。 在 Outlook 的說明框中鍵入「智慧引號」以找到它。
基於名稱的快速選擇
TAEF 允許使用 '/name' 命令列參數,在命令提示字元上根據名稱快速選取:
/name:<test name with wildcards>
相當於:
/select:@Name='<test name with wildcards>'
換句話說,您現在可以根據名稱提供選取查詢,例如:
Te.exe Examples\CPP.SelectionCriteria1.Example.dll Examples\CPP.SelectionCriteria2.Example.dll \
/select:"@Name='*::class11::*'"
使用 /name 可以更快,如下所示:
Te.exe Examples\CPP.SelectionCriteria1.Example.dll Examples\CPP.SelectionCriteria2.Example.dll /name=*::class11::*
請注意,如果命令提示字元中同時提供 /name 和 /select ,則會忽略 /name 並優先使用 /select。