選取項目
測試撰寫和執行架構 (TAEF) 提供一種機制,可根據您提供的元數據資訊選擇性地執行或省略特定測試。 下一節將逐步解說如何使用此選取機制搭配TE.exe的各種範例。
您可以從命令提示字元視窗執行TE.exe。
TE <test_binaries> [/select:<selection criteria>]
本節描述TE.exe /select:selection criteria 選項。 如需TE.exe的詳細資訊,請參閱 TE.exe 命令選項。
選取準則會全域套用至命令提示字元中提及的所有測試二進位檔。 讓我們考慮兩個test_binaries: Examples\CPP。 SelectionCriteria1.Example.dll和 Examples\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>” 的情況下會列為 “<<Namespace>::<ClassName”。<>Managed test_binaries 案例中的 ClassName>“。 同樣地,在原生test_binaries和 “Namespace” 中,測試方法名稱會列為 “<Namespace>::<ClassName>::<TestMethodName>”。<><ClassName>。<受管理test_binaries時,TestMethodName>”
換句話說,任何名稱或函式的完整名稱就是儲存在te中的內容。 這是允許唯一區分任何方法的能力。 例如,如果兩個類別具有相同的方法名稱,類別資格有助於唯一選取您感興趣的方法。 為此,選取準則有助於只執行符合指定test_binaries中準則的測試。
在上述範例中,如 Examples\Cpp.SelectionCriteria1.Example.dll所示,您可以依下列任一選取準則選擇 “Method111” :
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"
這隻會執行 Examples\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」。 因此,如果您有一個具有元數據 「property」 的函式,而另一個函式具有 「Property」,而選取準則正在尋找 “PROPERTY”,則會符合這兩個函式。
- 選取範圍查詢字串中的字串值應該包含在單引號中。 選取範圍查詢 “?” 中的字串值是單一通配符,而 “*” 是 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」 開頭(不區分大小寫)。 因此,上一個命令會在 Examples\CPP 中執行所有測試。SelectionCriteria1.Example.dll和 Examples\CPP 中的所有測試。類別 21 下的SelectionCriteria2.Example.dll (也就是 method211)
Te.exe Examples\CPP.SelectionCriteria1.Example.dll Examples\CPP.SelectionCriteria2.Example.dll \
/select:"not(@BackwardsCompatibility=*) OR (@Owner='C*' AND @BackwardsCompatibility='*XP*')"
會執行未指定BackwardsCompatibility的所有測試,或是擁有者名稱開頭為 “C” 且backwardsCompatibilty 值包含 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"
注意
這是使用 “>=”、“=>”、“<” 和 “<” 其中 propertyvalue 為 floatvalue 的良好範例。
在我們的範例中,這會執行 Examples\CPP 以外的所有方法。SelectionCriteria2.Example.dll - class22::method221,其中未指定 prority。 換句話說,這會執行:
- 範例\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 優先。