VSTest@2 - Visual Studio 测试 v2 任务

使用此任务可以使用 Visual Studio 测试 (VSTest) 运行器 (Selenium、Appium、编码 UI 测试等 ) 单元和功能测试。 可以运行具有 Visual Studio 测试适配器的测试框架。 示例框架包括 MSTest、xUnit、NUnit、Chutzpah (,用于使用 QUnit、Mocha 和 Jasmine) 等进行 JavaScript 测试。可以使用此任务 (版本 2) 在多个代理上分发测试。

语法

# 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 文件来运行有序测试和 Web 测试。 若要运行 .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 文件来运行有序测试和 Web 测试。 若要运行 .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 (由工具安装程序) 安装。 默认值:latest

指定要使用的 Visual Studio 测试版本。 如果指定 了 latest ,则此输入将从安装的允许值列表中选择最新版本 () 。 若要在代理上无需 Visual Studio 的情况下运行测试,请使用 “按工具安装”安装程序 选项。 请务必包含 Visual Studio 测试平台安装程序 任务,以便从 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 测试版本。 如果指定 了 latest ,则此输入将从安装的允许值列表中选择最新版本 () 。 若要在代理上无需 Visual Studio 的情况下运行测试,请使用 “按工具安装”安装程序 选项。 请务必包含 Visual Studio 测试平台安装程序 任务,以便从 NuGet 获取测试平台。


vstestLocation - vstest.console.exe路径
string. 可选。 在 时 vstestLocationMethod = location使用 。

指定 VSTest 的路径。


runSettingsFile - 设置文件
string.

指定要用于测试的 runsettingstestsettings 文件的路径。 对于 Visual Studio 15.7 及更高版本,请使用 runsettings 用于所有测试类型。 详细了解如何将文件转换为.testsettings.runsettings文件


overrideTestrunParameters - 替代测试运行参数
string.

重写在文件的 节runsettingsProperties文件的 节testsettingsTestRunParameters定义的参数。 例如:-key1 value1 -key2 value2注意:可以通过使用 Visual Studio 2017 (update 4 或更高版本) 访问TestContext文件中指定的testsettings属性。


pathtoCustomTestAdapters - 自定义测试适配器的路径
string.

指定自定义测试适配器的目录路径。 可自动发现与测试程序集位于同一文件夹中的适配器。


runInParallel - 在多核计算机上并行运行测试
boolean. 默认值:False

如果设置为 true,则并行运行测试,并利用计算机的可用核心。 如果已在runsettings文件中指定,MaxCpuCount这将替代 。 详细了解如何 并行运行测试


runTestsInIsolation - 单独运行测试
boolean. 默认值:False

在隔离的进程中运行测试。 这可能会导致 vstest.console.exe 测试过程中的错误更少,但测试运行速度可能会变慢。 使用多代理作业设置运行时,当前无法使用此选项。


codeCoverageEnabled - 已启用代码覆盖率
boolean. 默认值:False

从测试运行中收集代码覆盖率信息。


otherConsoleOptions - 其他控制台选项
string.

可传递给 vstest.console.exe 的其他控制台选项

这些选项不受支持,在使用代理作业 的多代理并行 设置运行测试、使用“ 测试计划 ”或“ 测试运行 ”选项运行测试或选择自定义批处理选项时,将忽略这些选项。 可改用设置文件指定这些选项。


distributionBatchType - 批处理测试
string. 允许的值: basedOnTestCases (基于测试和代理) 的数量, basedOnExecutionTime (基于测试) 的过去运行时间, basedOnAssembly (基于测试程序集) 。 默认值:basedOnTestCases

批处理是一组测试。 一批测试同时运行其测试,并发布批处理的结果。 如果运行任务的作业设置为使用多个代理,则每个代理将选取要并行运行的任何可用测试批次。 可以运行批处理:

基于测试和代理数。 基于参与测试运行的测试和代理数进行简单批处理。

基于过去运行测试的时间。 此批处理考虑过去的运行时间,以创建测试批,其中每个批处理的运行时间大致相等。

基于测试程序集。 程序集中的测试一起批处理。


batchingBasedOnAgentsOption - Batch 选项
string. 可选。 在 时 distributionBatchType = basedOnTestCases使用 。 允许的值: autoBatchSize (自动确定批大小) , customBatchSize (指定批大小) 。 默认值:autoBatchSize

根据参与测试运行的测试和代理数指定简单批处理。 自动确定批大小时,每个批都包含 (total number of tests / number of agents) 个测试。 如果指定了批大小,则每个批将包含指定数量的测试。


customBatchSizeValue - 每个批处理的测试数
string. 当 distributionBatchType = basedOnTestCases && batchingBasedOnAgentsOption = customBatchSize 时,需要此选项。 默认值:10

指定批大小。


batchingBasedOnExecutionTimeOption - Batch 选项
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 文件中指定适当的目标框架值,测试是否可以执行目标 .NET Core 框架。

可以使用此任务的版本 2 在多个代理上分发测试。 有关详细信息,请参阅使用 Visual Studio 测试任务并行运行测试

检查先决条件

如果使用 Windows 自承载代理,则必须安装以下先决条件:

需求

代理必须具有以下功能:

vstest

可以通过两种方式满足 vstest 需求:

  1. Visual Studio 安装在代理计算机上。
  2. 通过在管道定义中使用 Visual Studio 测试平台安装程序任务

如何运行使用 TestCase 作为数据源的测试?

若要运行使用 TestCase 作为数据源的自动测试,需要满足以下条件:

  1. 代理计算机上必须安装 Visual Studio 2017.6 或更高版本。 Visual Studio 测试平台安装程序任务不可用于运行使用 TestCase 作为数据源的测试。
  2. 创建授权用于“工作项(完整)”范围的 PAT
  3. 添加名为 Test.TestCaseAccessToken 的安全生成或发布变量,并将值设置为在上一步中创建的 PAT。

在使用某些任务选项运行数据驱动的 xUnit 和 NUnit 测试时遇到一些问题。 是否存在已知的限制?

使用 xUnit 和 NUnit 测试框架的数据驱动测试有一些已知的限制,不能与以下任务选项一起使用:

  1. 重新运行失败的测试。
  2. 在多个代理和批处理选项上分发测试。
  3. 测试影响分析。

上述限制是由于这些测试框架的适配器发现和报告数据驱动测试的方式所导致的。

VSTest 任务是否支持一次运行针对多个目标框架的测试?

是,从 VSTest 版本 17.3 开始,确实支持运行一次面向多个目标框架的测试。 在此之前,由于 VSTest 平台 端的限制,这是不可能的。

如果要运行属于多个目标框架的测试,则需要通过 Visual Studio 测试平台安装程序 安装兼容版本的 VSTest,并将其设置为 vsTestVersiontoolsInstaller 使用它。

发布测试结果时,收到以下错误:未能发布测试结果:指定的优先级无效?

如果任何测试方法的优先级设置为高于 255,则会发生此错误,请在代码中修复测试方法优先级,然后再次执行测试。 可以查看生成的 trx 文件,以查看优先级大于 255 的所有测试。

要求

要求 说明
管道类型 YAML,经典内部版本,经典版本
运行平台 Agent、DeploymentGroup
需求 自承载代理必须具有满足以下要求的功能才能运行使用此任务的作业:vstest
功能 此任务不满足作业中后续任务的任何要求。
命令限制 任意
可设置的变量 任意
代理版本 2.103.0 或更高版本
任务类别 测试