VSTest@2 - Visual Studio Test v2 工作

使用此工作來執行單元和功能測試, (Selenium、Appium、自動程式化 UI 測試等 ) 使用 Visual Studio Test (VSTest) 執行器。 您可以執行具有 Visual Studio 測試配接器的測試架構。 範例架構包括 MSTest、xUnit、NUnit、Chutzpah (,適用於使用 QUnit、Mocha 和 Jasmine) 等 JavaScript 測試。您可以使用這項工作 (第 2 版) ,在多個代理程式上散發測試。

Syntax

# Visual Studio Test v2
# Run unit and functional tests (Selenium, Appium, Coded UI test, etc.) using the Visual Studio Test (VsTest) runner. Test frameworks that have a Visual Studio test adapter such as MsTest, xUnit, NUnit, Chutzpah (for JavaScript tests using QUnit, Mocha and Jasmine), etc. can be run. Tests can be distributed on multiple agents using this task (version 2).
- task: VSTest@2
  inputs:
  # Test selection
    testSelector: 'testAssemblies' # 'testAssemblies' | 'testPlan' | 'testRun'. Required. Select tests using. Default: testAssemblies.
    testAssemblyVer2: # string. Required when testSelector = testAssemblies. Test files. 
    #testPlan: # string. Required when testSelector = testPlan. Test plan. 
    #testSuite: # string. Required when testSelector = testPlan. Test suite. 
    #testConfiguration: # string. Required when testSelector = testPlan. Test configuration. 
    #tcmTestRun: '$(test.RunId)' # string. Optional. Use when testSelector = testRun. Test Run. Default: $(test.RunId).
    searchFolder: '$(System.DefaultWorkingDirectory)' # string. Required. Search folder. Default: $(System.DefaultWorkingDirectory).
    #resultsFolder: '$(Agent.TempDirectory)\TestResults' # string. Test results folder. Default: $(Agent.TempDirectory)\TestResults.
    #testFiltercriteria: # string. Optional. Use when testSelector = testAssemblies. Test filter criteria. 
    #runOnlyImpactedTests: False # boolean. Optional. Use when testSelector = testAssemblies. Run only impacted tests. Default: False.
    #runAllTestsAfterXBuilds: '50' # string. Optional. Use when testSelector = testAssemblies && runOnlyImpactedTests = true. Number of builds after which all tests should be run. Default: 50.
    #uiTests: false # boolean. Test mix contains UI tests. Default: false.
  # Execution options
    #vstestLocationMethod: 'version' # 'version' | 'location'. Select test platform using. Default: version.
    #vsTestVersion: 'latest' # 'latest' | '17.0' | '16.0' | '15.0' | '14.0' | 'toolsInstaller'. Optional. Use when vstestLocationMethod = version. Test platform version. Default: latest.
    #vstestLocation: # string. Optional. Use when vstestLocationMethod = location. Path to vstest.console.exe. 
    #runSettingsFile: # string. Settings file. 
    #overrideTestrunParameters: # string. Override test run parameters. 
    #pathtoCustomTestAdapters: # string. Path to custom test adapters. 
    #runInParallel: False # boolean. Run tests in parallel on multi-core machines. Default: False.
    #runTestsInIsolation: False # boolean. Run tests in isolation. Default: False.
    #codeCoverageEnabled: False # boolean. Code coverage enabled. Default: False.
    #otherConsoleOptions: # string. Other console options. 
    #diagnosticsEnabled: false # boolean. Collect advanced diagnostics in case of catastrophic failures. Default: false.
    #collectDumpOn: 'onAbortOnly' # 'onAbortOnly' | 'always' | 'never'. Optional. Use when diagnosticsEnabled = true. Collect process dump and attach to test run report. Default: onAbortOnly.
    #rerunFailedTests: False # boolean. Rerun failed tests. Default: False.
    #rerunType: 'basedOnTestFailurePercentage' # 'basedOnTestFailurePercentage' | 'basedOnTestFailureCount'. Optional. Use when rerunFailedTests = true. Do not rerun if test failures exceed specified threshold. Default: basedOnTestFailurePercentage.
    #rerunFailedThreshold: '30' # string. Optional. Use when rerunFailedTests = true && rerunType = basedOnTestFailurePercentage. % failure. Default: 30.
    #rerunFailedTestCasesMaxLimit: '5' # string. Optional. Use when rerunFailedTests = true && rerunType = basedOnTestFailureCount. # of failed tests. Default: 5.
    #rerunMaxAttempts: '3' # string. Optional. Use when rerunFailedTests = true. Maximum # of attempts. Default: 3.
  # Advanced execution options
    #distributionBatchType: 'basedOnTestCases' # 'basedOnTestCases' | 'basedOnExecutionTime' | 'basedOnAssembly'. Batch tests. Default: basedOnTestCases.
    #batchingBasedOnAgentsOption: 'autoBatchSize' # 'autoBatchSize' | 'customBatchSize'. Optional. Use when distributionBatchType = basedOnTestCases. Batch options. Default: autoBatchSize.
    #customBatchSizeValue: '10' # string. Required when distributionBatchType = basedOnTestCases && batchingBasedOnAgentsOption = customBatchSize. Number of tests per batch. Default: 10.
    #batchingBasedOnExecutionTimeOption: 'autoBatchSize' # 'autoBatchSize' | 'customTimeBatchSize'. Optional. Use when distributionBatchType = basedOnExecutionTime. Batch options. Default: autoBatchSize.
    #customRunTimePerBatchValue: '60' # string. Required when distributionBatchType = basedOnExecutionTime && batchingBasedOnExecutionTimeOption = customTimeBatchSize. Running time (sec) per batch. Default: 60.
    #dontDistribute: False # boolean. Replicate tests instead of distributing when multiple agents are used in the job. Default: False.
  # Reporting options
    #testRunTitle: # string. Test run title. 
    #platform: # string. Build platform. 
    #configuration: # string. Build configuration. 
    #publishRunAttachments: true # boolean. Upload test attachments. Default: true.
    #failOnMinTestsNotRun: False # boolean. Fail the task if a minimum number of tests are not run. Default: False.
    #minimumExpectedTests: '1' # string. Optional. Use when failOnMinTestsNotRun = true. Minimum # of tests. Default: 1.
# Visual Studio Test v2
# Run unit and functional tests (Selenium, Appium, Coded UI test, etc.) using the Visual Studio Test (VsTest) runner. Test frameworks that have a Visual Studio test adapter such as MsTest, xUnit, NUnit, Chutzpah (for JavaScript tests using QUnit, Mocha and Jasmine), etc. can be run. Tests can be distributed on multiple agents using this task (version 2).
- task: VSTest@2
  inputs:
  # Test selection
    testSelector: 'testAssemblies' # 'testAssemblies' | 'testPlan' | 'testRun'. Required. Select tests using. Default: testAssemblies.
    testAssemblyVer2: # string. Required when testSelector = testAssemblies. Test files. 
    #testPlan: # string. Required when testSelector = testPlan. Test plan. 
    #testSuite: # string. Required when testSelector = testPlan. Test suite. 
    #testConfiguration: # string. Required when testSelector = testPlan. Test configuration. 
    #tcmTestRun: '$(test.RunId)' # string. Optional. Use when testSelector = testRun. Test Run. Default: $(test.RunId).
    searchFolder: '$(System.DefaultWorkingDirectory)' # string. Required. Search folder. Default: $(System.DefaultWorkingDirectory).
    #resultsFolder: '$(Agent.TempDirectory)\TestResults' # string. Test results folder. Default: $(Agent.TempDirectory)\TestResults.
    #testFiltercriteria: # string. Optional. Use when testSelector = testAssemblies. Test filter criteria. 
    #runOnlyImpactedTests: False # boolean. Optional. Use when testSelector = testAssemblies. Run only impacted tests. Default: False.
    #runAllTestsAfterXBuilds: '50' # string. Optional. Use when testSelector = testAssemblies && runOnlyImpactedTests = true. Number of builds after which all tests should be run. Default: 50.
    #uiTests: false # boolean. Test mix contains UI tests. Default: false.
  # Execution options
    #vstestLocationMethod: 'version' # 'version' | 'location'. Select test platform using. Default: version.
    #vsTestVersion: 'latest' # 'latest' | '16.0' | '15.0' | '14.0' | 'toolsInstaller'. Optional. Use when vstestLocationMethod = version. Test platform version. Default: latest.
    #vstestLocation: # string. Optional. Use when vstestLocationMethod = location. Path to vstest.console.exe. 
    #runSettingsFile: # string. Settings file. 
    #overrideTestrunParameters: # string. Override test run parameters. 
    #pathtoCustomTestAdapters: # string. Path to custom test adapters. 
    #runInParallel: False # boolean. Run tests in parallel on multi-core machines. Default: False.
    #runTestsInIsolation: False # boolean. Run tests in isolation. Default: False.
    #codeCoverageEnabled: False # boolean. Code coverage enabled. Default: False.
    #otherConsoleOptions: # string. Other console options. 
    #diagnosticsEnabled: false # boolean. Collect advanced diagnostics in case of catastrophic failures. Default: false.
    #collectDumpOn: 'onAbortOnly' # 'onAbortOnly' | 'always' | 'never'. Optional. Use when diagnosticsEnabled = true. Collect process dump and attach to test run report. Default: onAbortOnly.
    #rerunFailedTests: False # boolean. Rerun failed tests. Default: False.
    #rerunType: 'basedOnTestFailurePercentage' # 'basedOnTestFailurePercentage' | 'basedOnTestFailureCount'. Optional. Use when rerunFailedTests = true. Do not rerun if test failures exceed specified threshold. Default: basedOnTestFailurePercentage.
    #rerunFailedThreshold: '30' # string. Optional. Use when rerunFailedTests = true && rerunType = basedOnTestFailurePercentage. % failure. Default: 30.
    #rerunFailedTestCasesMaxLimit: '5' # string. Optional. Use when rerunFailedTests = true && rerunType = basedOnTestFailureCount. # of failed tests. Default: 5.
    #rerunMaxAttempts: '3' # string. Optional. Use when rerunFailedTests = true. Maximum # of attempts. Default: 3.
  # Advanced execution options
    #distributionBatchType: 'basedOnTestCases' # 'basedOnTestCases' | 'basedOnExecutionTime' | 'basedOnAssembly'. Batch tests. Default: basedOnTestCases.
    #batchingBasedOnAgentsOption: 'autoBatchSize' # 'autoBatchSize' | 'customBatchSize'. Optional. Use when distributionBatchType = basedOnTestCases. Batch options. Default: autoBatchSize.
    #customBatchSizeValue: '10' # string. Required when distributionBatchType = basedOnTestCases && batchingBasedOnAgentsOption = customBatchSize. Number of tests per batch. Default: 10.
    #batchingBasedOnExecutionTimeOption: 'autoBatchSize' # 'autoBatchSize' | 'customTimeBatchSize'. Optional. Use when distributionBatchType = basedOnExecutionTime. Batch options. Default: autoBatchSize.
    #customRunTimePerBatchValue: '60' # string. Required when distributionBatchType = basedOnExecutionTime && batchingBasedOnExecutionTimeOption = customTimeBatchSize. Running time (sec) per batch. Default: 60.
    #dontDistribute: False # boolean. Replicate tests instead of distributing when multiple agents are used in the job. Default: False.
  # Reporting options
    #testRunTitle: # string. Test run title. 
    #platform: # string. Build platform. 
    #configuration: # string. Build configuration. 
    #publishRunAttachments: true # boolean. Upload test attachments. Default: true.
    #failOnMinTestsNotRun: False # boolean. Fail the task if a minimum number of tests are not run. Default: False.
    #minimumExpectedTests: '1' # string. Optional. Use when failOnMinTestsNotRun = true. Minimum # of tests. Default: 1.
# Visual Studio Test v2
# Run unit and functional tests (Selenium, Appium, Coded UI test, etc.) using the Visual Studio Test (VsTest) runner. Test frameworks that have a Visual Studio test adapter such as MsTest, xUnit, NUnit, Chutzpah (for JavaScript tests using QUnit, Mocha and Jasmine), etc. can be run. Tests can be distributed on multiple agents using this task (version 2).
- task: VSTest@2
  inputs:
  # Test selection
    testSelector: 'testAssemblies' # 'testAssemblies' | 'testPlan' | 'testRun'. Required. Select tests using. Default: testAssemblies.
    testAssemblyVer2: # string. Required when testSelector = testAssemblies. Test files. 
    #testPlan: # string. Required when testSelector = testPlan. Test plan. 
    #testSuite: # string. Required when testSelector = testPlan. Test suite. 
    #testConfiguration: # string. Required when testSelector = testPlan. Test configuration. 
    #tcmTestRun: '$(test.RunId)' # string. Optional. Use when testSelector = testRun. Test Run. Default: $(test.RunId).
    searchFolder: '$(System.DefaultWorkingDirectory)' # string. Required. Search folder. Default: $(System.DefaultWorkingDirectory).
    #testFiltercriteria: # string. Optional. Use when testSelector = testAssemblies. Test filter criteria. 
    #runOnlyImpactedTests: False # boolean. Optional. Use when testSelector = testAssemblies. Run only impacted tests. Default: False.
    #runAllTestsAfterXBuilds: '50' # string. Optional. Use when testSelector = testAssemblies && runOnlyImpactedTests = true. Number of builds after which all tests should be run. Default: 50.
    #uiTests: false # boolean. Test mix contains UI tests. Default: false.
  # Execution options
    #vstestLocationMethod: 'version' # 'version' | 'location'. Select test platform using. Default: version.
    #vsTestVersion: 'latest' # 'latest' | '16.0' | '15.0' | '14.0' | 'toolsInstaller'. Optional. Use when vstestLocationMethod = version. Test platform version. Default: latest.
    #vstestLocation: # string. Optional. Use when vstestLocationMethod = location. Path to vstest.console.exe. 
    #runSettingsFile: # string. Settings file. 
    #overrideTestrunParameters: # string. Override test run parameters. 
    #pathtoCustomTestAdapters: # string. Path to custom test adapters. 
    #runInParallel: False # boolean. Run tests in parallel on multi-core machines. Default: False.
    #runTestsInIsolation: False # boolean. Run tests in isolation. Default: False.
    #codeCoverageEnabled: False # boolean. Code coverage enabled. Default: False.
    #otherConsoleOptions: # string. Other console options. 
    #diagnosticsEnabled: false # boolean. Collect advanced diagnostics in case of catastrophic failures. Default: false.
    #collectDumpOn: 'onAbortOnly' # 'onAbortOnly' | 'always' | 'never'. Optional. Use when diagnosticsEnabled = true. Collect process dump and attach to test run report. Default: onAbortOnly.
    #rerunFailedTests: False # boolean. Rerun failed tests. Default: False.
    #rerunType: 'basedOnTestFailurePercentage' # 'basedOnTestFailurePercentage' | 'basedOnTestFailureCount'. Optional. Use when rerunFailedTests = true. Do not rerun if test failures exceed specified threshold. Default: basedOnTestFailurePercentage.
    #rerunFailedThreshold: '30' # string. Optional. Use when rerunFailedTests = true && rerunType = basedOnTestFailurePercentage. % failure. Default: 30.
    #rerunFailedTestCasesMaxLimit: '5' # string. Optional. Use when rerunFailedTests = true && rerunType = basedOnTestFailureCount. # of failed tests. Default: 5.
    #rerunMaxAttempts: '3' # string. Optional. Use when rerunFailedTests = true. Maximum # of attempts. Default: 3.
  # Advanced execution options
    #distributionBatchType: 'basedOnTestCases' # 'basedOnTestCases' | 'basedOnExecutionTime' | 'basedOnAssembly'. Batch tests. Default: basedOnTestCases.
    #batchingBasedOnAgentsOption: 'autoBatchSize' # 'autoBatchSize' | 'customBatchSize'. Optional. Use when distributionBatchType = basedOnTestCases. Batch options. Default: autoBatchSize.
    #customBatchSizeValue: '10' # string. Required when distributionBatchType = basedOnTestCases && batchingBasedOnAgentsOption = customBatchSize. Number of tests per batch. Default: 10.
    #batchingBasedOnExecutionTimeOption: 'autoBatchSize' # 'autoBatchSize' | 'customTimeBatchSize'. Optional. Use when distributionBatchType = basedOnExecutionTime. Batch options. Default: autoBatchSize.
    #customRunTimePerBatchValue: '60' # string. Required when distributionBatchType = basedOnExecutionTime && batchingBasedOnExecutionTimeOption = customTimeBatchSize. Running time (sec) per batch. Default: 60.
    #dontDistribute: False # boolean. Replicate tests instead of distributing when multiple agents are used in the job. Default: False.
  # Reporting options
    #testRunTitle: # string. Test run title. 
    #platform: # string. Build platform. 
    #configuration: # string. Build configuration. 
    #publishRunAttachments: true # boolean. Upload test attachments. Default: true.
# Visual Studio Test v2
# Run unit and functional tests (Selenium, Appium, Coded UI test, etc.) using the Visual Studio Test (VsTest) runner. Test frameworks that have a Visual Studio test adapter such as MsTest, xUnit, NUnit, Chutzpah (for JavaScript tests using QUnit, Mocha and Jasmine), etc. can be run. Tests can be distributed on multiple agents using this task (version 2).
- task: VSTest@2
  inputs:
  # Test selection
    testSelector: 'testAssemblies' # 'testAssemblies' | 'testPlan' | 'testRun'. Required. Select tests using. Default: testAssemblies.
    testAssemblyVer2: # string. Required when testSelector = testAssemblies. Test files. 
    #testPlan: # string. Required when testSelector = testPlan. Test plan. 
    #testSuite: # string. Required when testSelector = testPlan. Test suite. 
    #testConfiguration: # string. Required when testSelector = testPlan. Test configuration. 
    #tcmTestRun: '$(test.RunId)' # string. Optional. Use when testSelector = testRun. Test Run. Default: $(test.RunId).
    searchFolder: '$(System.DefaultWorkingDirectory)' # string. Required. Search folder. Default: $(System.DefaultWorkingDirectory).
    #testFiltercriteria: # string. Optional. Use when testSelector = testAssemblies. Test filter criteria. 
    #runOnlyImpactedTests: False # boolean. Optional. Use when testSelector = testAssemblies. Run only impacted tests. Default: False.
    #runAllTestsAfterXBuilds: '50' # string. Optional. Use when testSelector = testAssemblies && runOnlyImpactedTests = true. Number of builds after which all tests should be run. Default: 50.
    #uiTests: false # boolean. Test mix contains UI tests. Default: false.
  # Execution options
    #vstestLocationMethod: 'version' # 'version' | 'location'. Select test platform using. Default: version.
    #vsTestVersion: 'latest' # 'latest' | '16.0' | '15.0' | '14.0' | 'toolsInstaller'. Optional. Use when vstestLocationMethod = version. Test platform version. Default: latest.
    #vstestLocation: # string. Optional. Use when vstestLocationMethod = location. Path to vstest.console.exe. 
    #runSettingsFile: # string. Settings file. 
    #overrideTestrunParameters: # string. Override test run parameters. 
    #pathtoCustomTestAdapters: # string. Path to custom test adapters. 
    #runInParallel: False # boolean. Run tests in parallel on multi-core machines. Default: False.
    #runTestsInIsolation: False # boolean. Run tests in isolation. Default: False.
    #codeCoverageEnabled: False # boolean. Code coverage enabled. Default: False.
    #otherConsoleOptions: # string. Other console options. 
    #diagnosticsEnabled: True # boolean. Collect advanced diagnostics in case of catastrophic failures. Default: True.
    #collectDumpOn: 'onAbortOnly' # 'onAbortOnly' | 'always' | 'never'. Optional. Use when diagnosticsEnabled = true. Collect process dump and attach to test run report. Default: onAbortOnly.
    #rerunFailedTests: False # boolean. Rerun failed tests. Default: False.
    #rerunType: 'basedOnTestFailurePercentage' # 'basedOnTestFailurePercentage' | 'basedOnTestFailureCount'. Optional. Use when rerunFailedTests = true. Do not rerun if test failures exceed specified threshold. Default: basedOnTestFailurePercentage.
    #rerunFailedThreshold: '30' # string. Optional. Use when rerunFailedTests = true && rerunType = basedOnTestFailurePercentage. % failure. Default: 30.
    #rerunFailedTestCasesMaxLimit: '5' # string. Optional. Use when rerunFailedTests = true && rerunType = basedOnTestFailureCount. # of failed tests. Default: 5.
    #rerunMaxAttempts: '3' # string. Optional. Use when rerunFailedTests = true. Maximum # of attempts. Default: 3.
  # Advanced execution options
    #distributionBatchType: 'basedOnTestCases' # 'basedOnTestCases' | 'basedOnExecutionTime' | 'basedOnAssembly'. Batch tests. Default: basedOnTestCases.
    #batchingBasedOnAgentsOption: 'autoBatchSize' # 'autoBatchSize' | 'customBatchSize'. Optional. Use when distributionBatchType = basedOnTestCases. Batch options. Default: autoBatchSize.
    #customBatchSizeValue: '10' # string. Required when distributionBatchType = basedOnTestCases && batchingBasedOnAgentsOption = customBatchSize. Number of tests per batch. Default: 10.
    #batchingBasedOnExecutionTimeOption: 'autoBatchSize' # 'autoBatchSize' | 'customTimeBatchSize'. Optional. Use when distributionBatchType = basedOnExecutionTime. Batch options. Default: autoBatchSize.
    #customRunTimePerBatchValue: '60' # string. Required when distributionBatchType = basedOnExecutionTime && batchingBasedOnExecutionTimeOption = customTimeBatchSize. Running time (sec) per batch. Default: 60.
    #dontDistribute: False # boolean. Do not distribute tests and replicate instead when multiple agents are used in the job. Default: False.
  # Reporting options
    #testRunTitle: # string. Test run title. 
    #platform: # string. Build platform. 
    #configuration: # string. Build configuration. 
    #publishRunAttachments: true # boolean. Upload test attachments. Default: true.

輸入

testSelector - 使用選取測試
string. 必要。 允許的值: testAssemblies (測試元件) 、 testPlan (測試計劃) , testRun (測試回合) 。 預設值:testAssemblies

  • 測試元件: 指定一或多個包含測試的測試元件。 您可以選擇性地指定篩選準則,只選取特定的測試。
  • 測試計劃: 從測試計劃執行測試,其具有與其相關聯的自動化測試方法。 若要深入瞭解如何將測試與測試案例工作專案產生關聯,請參閱 建立自動化測試與測試案例的關聯
  • 測試回合: 當您設定環境以從 測試計劃執行測試時,請使用此選項。 在持續整合/持續部署 (CI/CD) 管線中執行測試時,不應該使用此選項。

testAssemblyVer2 - 測試檔案
string. 當 testSelector = testAssemblies 時為必要。 預設值:**\bin\**\*test.dll\n**\bin\**\*tests.dll

從指定的檔案執行測試。 您可以分別指定和檔案來執行 .orderedtest 已排序的測試與 .webtest Webtest。 若要執行 .webtest,需要 Visual Studio 2017 Update 4 或更高版本。 檔案路徑相對於搜尋資料夾。 此輸入支援多行 迷你配對模式

# Example
- task: VSTest@2
  inputs:
    testSelector: 'testAssemblies'
    testAssemblyVer2: |
      **\*test*.dll
      !**\*TestAdapter.dll
      !**\obj\**

testAssemblyVer2 - 測試檔案
string. 當 testSelector = testAssemblies 時為必要。 預設值:**\*test*.dll\n!**\*TestAdapter.dll\n!**\obj\**

從指定的檔案執行測試。 您可以分別指定和檔案來執行 .orderedtest 已排序的測試與 .webtest Webtest。 若要執行 .webtest,需要 Visual Studio 2017 Update 4 或更高版本。 檔案路徑相對於搜尋資料夾。 此輸入支援多行 迷你配對模式

# Example
- task: VSTest@2
  inputs:
    testSelector: 'testAssemblies'
    testAssemblyVer2: |
      **\*test*.dll
      !**\*TestAdapter.dll
      !**\obj\**

testPlan - 測試計劃
string. 當 testSelector = testPlan 時為必要。

指定測試計劃,其中包含具有自動化測試案例的測試套件。


testSuite - 測試套件
string. 當 testSelector = testPlan 時為必要。

指定一或多個包含自動化測試案例的測試套件。 測試案例工作項目必須與 自動化測試方法相關聯。


testConfiguration - 測試組態
string. 當 testSelector = testPlan 時為必要。

指定測試組態。


tcmTestRun - 測試回合
string. 選擇性。 使用時機 testSelector = testRun。 預設值:$(test.RunId)

指定從 測試計劃觸發自動化測試回合時所使用的測試回合型選取專案。 此選項無法用於在 CI/CD 管線中執行測試。


searchFolder - 搜尋資料夾
string. 必要。 預設值:$(System.DefaultWorkingDirectory)

指定要搜尋測試元件的資料夾。


resultsFolder - 測試結果資料夾
string. 預設值:$(Agent.TempDirectory)\TestResults

指定要儲存測試結果的資料夾。 使用預設目錄時,會在管線執行結束時加以清除。 在測試執行之前,一律會在工作開始時 vstest 清除結果目錄。 如果提供,則會將相對資料夾路徑視為相對於 $(Agent.TempDirectory)


testFiltercriteria - 測試篩選準則
string. 選擇性。 使用時機 testSelector = testAssemblies

指定從測試元件篩選測試的其他準則。 例如:Priority=1|Name=MyTestMethod。 瞭解 命令行選項


runOnlyImpactedTests - 僅執行受影響的測試
boolean. 選擇性。 使用時機 testSelector = testAssemblies。 預設值:False

自動指定並執行驗證程式代碼變更所需的測試。 瞭解如何使用 測試影響分析


runAllTestsAfterXBuilds - 應該在其中執行所有測試的組建數目
string. 選擇性。 使用時機 testSelector = testAssemblies && runOnlyImpactedTests = true。 預設值:50

指定要在自動執行所有測試之前執行的組建數目。 測試影響分析會儲存測試案例與原始碼之間的對應。 建議您定期執行所有測試來重新產生對應。


uiTests - 測試混合包含UI測試
boolean. 預設值:false

若要執行 UI 測試,請確定代理程式已設定為在啟用 Autologon互動式模式中執行。 設定代理程式以互動方式執行必須先完成,才能將組建/發行排入佇列。 核取此方塊不會自動在互動式模式中設定代理程式。 此選項可作為適當設定代理程式的提醒,以避免發生失敗。 VS 2015 和 2017 集區的託管 Windows 代理程式可用來執行 UI 測試。


vstestLocationMethod - 使用選取測試平臺
string. 允許的值: versionlocation (特定位置) 。 預設值:version

指定要使用的測試平臺。


vsTestVersion - 測試平臺版本
string. 選擇性。 使用時機 vstestLocationMethod = version。 允許的值: latest17.0 (Visual Studio 2022) 、 16.0 (Visual Studio 2019) 、 15.0 (Visual Studio 2017) 、 14.0 (Visual Studio 2015) , toolsInstaller (Tools Installer) 安裝。 預設值:latest

指定要使用的Visual Studio Test 版本。 如果指定 latest ,則此輸入會從已安裝的允許值清單中選擇最新版本 () 。 若要在代理程式上執行測試而不需 Visual Studio,請使用 [ 由工具安裝] 安裝程式 選項。 請務必包含 Visual Studio Test Platform Installer 工作,以從 NuGet 取得測試平臺。


vsTestVersion - 測試平臺版本
string. 選擇性。 使用 時 vstestLocationMethod = version。 允許的值: latest16.0 (Visual Studio 2019) 、 15.0 (Visual Studio 2017) 、 14.0 (Visual Studio 2015) , toolsInstaller (Tools Installer 安裝) 。 預設值:latest

指定要使用的Visual Studio Test 版本。 如果指定 了 latest ,此輸入會從已安裝的允許值清單中選擇最新版本) (。 若要在代理程式上執行不需要 Visual Studio 的測試,請使用 [ 工具安裝] 安裝程式 選項。 請務必包含 Visual Studio Test Platform Installer 工作,以從 NuGet 取得測試平臺。


vstestLocation - vstest.console.exe的路徑
string. 選擇性。 使用 時 vstestLocationMethod = location

指定 VSTest 的路徑。


runSettingsFile - 配置檔
string.

指定要搭配測試使用的 或 testsettings 檔案路徑runsettings。 針對 Visual Studio 15.7 和更新版本,適用於所有 runsettings 測試類型。 深入瞭解 如何將 .testsettings 檔案 .runsettings 轉換成檔案


overrideTestrunParameters - 覆寫測試回合參數
string.

覆寫檔案區段runsettingsProperties檔案區段testsettings中所TestRunParameters定義的參數。 例如:-key1 value1 -key2 value2注意:使用 Visual Studio 2017 (更新 4 或更新版本) ,即可存取TestContext檔案中指定的testsettings屬性。


pathtoCustomTestAdapters - 自訂測試配接器的路徑
string.

指定自訂測試配接器的目錄路徑。 會自動探索位於與測試元件相同的資料夾中的配接器。


runInParallel - 在多核心計算機上平行執行測試
boolean. 預設值:False

如果設定為 true,測試會以平行方式執行,並利用機器的可用核心。 這會覆寫 MaxCpuCount 檔案 runsettings 中指定的 。 深入瞭解如何 平行執行測試


runTestsInIsolation - 隔離執行測試
boolean. 預設值:False

在獨立的處理序中執行測試。 這可能會導致 vstest.console.exe 測試程式中的錯誤較少,但測試的執行速度可能會變慢。 使用多代理程式作業設定執行時,目前無法使用此選項。


codeCoverageEnabled - 已啟用程式代碼涵蓋範圍
boolean. 預設值:False

從測試回合收集程式代碼涵蓋範圍資訊。


otherConsoleOptions - 其他主控台選項
string.

其他可傳遞至 vstest.console.exe 的控制台選項

不支援這些選項,而且在使用代理程式作業的多 代理程式平行 設定執行測試、使用 [測試計劃 ] 或 [ 測試回合 ] 選項執行測試時,或選取自定義批處理選項時,將會忽略這些選項。 您可以改用設定檔來指定選項。


distributionBatchType - 批次測試
string. 允許的值: basedOnTestCases (根據測試與代理程式的數目) , basedOnExecutionTime (根據測試) 的過去運行時間, basedOnAssembly (根據測試元件) 。 預設值:basedOnTestCases

批次是一組測試。 測試批次會同時執行其測試,並針對批次發佈結果。 如果工作執行所在的作業設定為使用多個代理程式,則每個代理程式都會挑選任何可用的測試批次,以平行方式執行。 您可以執行批次:

根據測試和代理程式的數目。 根據參與測試回合的測試數目和代理程式數目,進行簡單的批處理。

根據測試的過去運行時間。 此批處理會考慮過去運行時間,以建立每個批次大約相等運行時間的測試批次。

以測試元件為基礎。 來自元件的測試會一起批處理。


batchingBasedOnAgentsOption - 批次選項
string. 選擇性。 使用 時 distributionBatchType = basedOnTestCases。 允許的值: autoBatchSize (自動判斷批次大小) , customBatchSize (指定批次大小) 。 預設值:autoBatchSize

根據參與測試回合的測試與代理程式數目,指定簡單的批處理。 自動判斷批次大小時,每個批次都包含 (total number of tests / number of agents) 測試。 如果指定批次大小,則每個批次都會包含指定的測試數目。


customBatchSizeValue - 每個批次的測試數目
string. 當 distributionBatchType = basedOnTestCases && batchingBasedOnAgentsOption = customBatchSize 時為必要。 預設值:10

指定批次大小。


batchingBasedOnExecutionTimeOption - 批次選項
string. 選擇性。 使用 時 distributionBatchType = basedOnExecutionTime。 允許的值: autoBatchSize (自動判斷批次時間) , customTimeBatchSize (指定每個批次的運行時間) 。 預設值:autoBatchSize

此批處理會考慮過去的運行時間,以建立每個批次大約相等運行時間的測試批次。 快速執行的測試將會一起批處理,而長時間執行的測試可能屬於個別的批次。 當此選項與多代理程式作業設定搭配使用時,總測試時間會縮減為最小值。


customRunTimePerBatchValue - 每個批次的運行時間 (秒)
string. 當 distributionBatchType = basedOnExecutionTime && batchingBasedOnExecutionTimeOption = customTimeBatchSize 時為必要。 預設值:60

指定每個批次) (的運行時間。


dontDistribute - 復寫測試,而不是在作業中使用多個代理程式時散發
boolean. 預設值:False

當工作在多代理程式作業中執行時,選擇此選項不會將測試分散到代理程式。 每個選取的測試 (都會在每個代理程式上重複) 。 當代理程式作業設定為不使用平行處理原則或多重組態選項執行時,此選項不適用。


dontDistribute - 請勿在作業中使用多個代理程式時散發測試和複寫
boolean. 預設值:False

當工作在多代理程式作業中執行時,選擇此選項不會將測試分散到代理程式。 每個選取的測試 (都會在每個代理程式上重複) 。 當代理程式作業設定為不使用平行處理原則或多重組態選項執行時,此選項不適用。


testRunTitle - 測試回合標題
string.

指定測試回合的名稱。


platform - 建置平臺
string.

指定應該報告測試的組建平臺。 如果您已在建置工作中定義平臺的變數,請使用該變數搭配此輸入。


configuration - 組建組態
string.

指定應該報告測試的組建組態。 如果您已在建置工作中定義組態的變數,請使用該變數搭配此輸入。


publishRunAttachments - 上傳測試附件
boolean. 預設值:true

加入加入或退出發佈執行層級附件。


failOnMinTestsNotRun - 如果未執行最少的測試數目,工作會失敗。
boolean. 預設值:False

如果未執行最少的測試數目,工作就會失敗。 如果工作輸入或基礎測試配接器相依性有任何變更,則這可能很有用,但只會找到所需的測試子集。


minimumExpectedTests - 測試數目下限
string. 選擇性。 使用時機 failOnMinTestsNotRun = true。 預設值:1

指定要讓工作成功執行的測試數目下限。 執行的總測試會計算為通過、失敗和中止的測試總和。


diagnosticsEnabled - 收集嚴重失敗時的進階診斷
boolean. 預設值:false

收集診斷數據以針對重大失敗進行疑難解答,例如測試損毀。 核取此選項時,會產生序列 XML 檔案並附加至測試回合。 此順序檔案包含測試已執行之序列的相關信息,因此可以識別潛在的原因測試。


diagnosticsEnabled - 收集嚴重失敗時的進階診斷
boolean. 預設值:True

收集診斷數據以針對重大失敗進行疑難解答,例如測試損毀。 核取此選項時,會產生序列 XML 檔案並附加至測試回合。 此順序檔案包含測試已執行之序列的相關信息,因此可以識別潛在的原因測試。


collectDumpOn - 收集進程傾印並附加至測試回合報告
string. 選擇性。 使用時機 diagnosticsEnabled = true。 允許的值: onAbortOnly (僅中止) 、、 alwaysnever。 預設值:onAbortOnly

收集可用於進一步分析的迷你傾印。

  • onAbortOnly - 只有在測試回合中止時,才會收集迷你傾印。
  • 一律 - 不論測試回合是否完成,一律會收集迷你傾印。
  • 永不 - 不論測試回合是否完成,都不會收集迷你傾印。

rerunFailedTests - 重新執行失敗的測試
boolean. 預設值:False

重新執行任何失敗的測試,直到通過或達到嘗試次數上限為止。


rerunType - 如果測試失敗超過指定的臨界值,請勿重新執行
string. 選擇性。 使用時機 rerunFailedTests = true。 允許的值: basedOnTestFailurePercentage (% 失敗) , basedOnTestFailureCount (# 失敗的測試) 。 預設值:basedOnTestFailurePercentage

避免在失敗率超過指定的臨界值時重新執行測試。 如果環境問題導致大量失敗,就適用此情況。 您可以將失敗百分比或失敗的測試數目指定為臨界值。


rerunFailedThreshold - % 失敗
string. 選擇性。 使用時機 rerunFailedTests = true && rerunType = basedOnTestFailurePercentage。 預設值:30

當失敗的測試案例百分比超過指定的臨界值時,避免重新執行測試。 如果環境問題導致大量失敗,就適用此情況。


rerunFailedTestCasesMaxLimit - 失敗的測試數目
string. 選擇性。 使用時機 rerunFailedTests = true && rerunType = basedOnTestFailureCount。 預設值:5

當失敗的測試案例數目超過指定的限制時,避免重新執行測試。 如果環境問題導致大量失敗,就適用此情況。


rerunMaxAttempts - 嘗試次數上限
string. 選擇性。 使用時機 rerunFailedTests = true。 預設值:3

指定重試失敗測試的次數上限。 如果在達到嘗試次數上限之前通過測試,將不會再次重新執行。


工作控制選項

除了工作輸入之外,所有工作都有控制選項。 如需詳細資訊,請參閱 控件選項和一般工作屬性

輸出變數

無。

備註

使用此工作,使用 Visual Studio 測試執行器 (Selenium、Appium、自動程式化 UI 測試等) 執行單元和功能測試。 除了 MSTest 型測試之外,也可以執行具有 Visual Studio 測試配接器的測試架構,例如 xUnit、NUnit 或 Chutzpah。

藉由在 .runsettings 檔案中指定適當的目標 Framework 值,測試是否可以執行目標 .NET Core 架構。

測試可以使用這項工作第 2 版在多個代理程式上散發。 如需詳細資訊,請參閱 使用Visual Studio測試工作平行執行測試

檢查先決條件

如果您使用 Windows 自我載入代理程式,則必須安裝此必要條件:

要求

代理程式必須具備下列功能:

vstest

vstest 需求可以透過兩種方式滿足:

  1. Visual Studio 會安裝在代理程式電腦上。
  2. 在管線定義中使用 Visual Studio Test Platform Installer 工作

如何執行使用TestCase作為數據源的測試?

若要執行使用 TestCase 作為資料源的自動化測試,需要下列專案:

  1. 代理程式計算機上必須有 Visual Studio 2017.6 或更高版本。 Visual Studio Test Platform Installer 工作無法用來執行使用 TestCase 作為數據源的測試。
  2. 建立已獲授權範圍「工作專案 (完整) 」的 PAT
  3. 新增名為 Test.TestCaseAccessToken 的安全組建或發行變數,並將值設定為在上一個步驟中建立的 PAT。

我在使用一些工作選項執行數據驅動 xUnit 和 NUnit 測試時遇到問題。 是否有已知的限制?

使用 xUnit 和 NUnit 測試架構的數據驅動測試有一些已知的限制,無法搭配下列工作選項使用:

  1. 重新執行失敗的測試。
  2. 在多個代理程式和批處理選項上散發測試。
  3. 測試影響分析。

上述限制是因為這些測試架構的配接器如何探索和報告數據驅動測試。

VSTest 工作是否支援一次執行以多個目標架構為目標的測試?

是,從 VSTest 版本 17.3 開始,支援一次執行以多個目標架構為目標的測試。 在這之前,由於 VSTest 平臺 端的限制,因此無法達成此目標。

如果您想要執行屬於多個目標架構的測試,您必須透過 Visual Studio Test Platform Installer 安裝相容的 VSTest 版本,並將 設定 vsTestVersiontoolsInstaller 來使用它。

發佈測試結果時,收到此錯誤:無法發佈測試結果:指定的優先順序無效?

如果任何測試方法的優先順序設定高於 255,請修正程式代碼中的測試方法優先順序,然後再次執行測試,就會發生此錯誤。 您可以檢閱產生的 trx 檔案,以查看優先順序大於 255 的所有測試。

規格需求

需求 描述
管線類型 YAML、傳統組建、傳統版本
在上執行 Agent、DeploymentGroup
要求 自我裝載代理程式必須具備符合下列需求的功能,才能執行使用此工作的工作:vstest
Capabilities 此工作不符合作業中後續工作的任何需求。
命令限制 任何
可設定變數 任何
代理程式版本 2.103.0 或更新版本
工作類別 測試