gpt4 book ai didi

nunit - 如何在 VSTS 中使用 NUnit?

转载 作者:行者123 更新时间:2023-12-01 01:53:48 25 4
gpt4 key购买 nike

我正在尝试在 Visual Studio Team System 中使用 NUnit 3,他们似乎很难做到这一点。我已将测试程序集步骤添加到构建过程中,并在高级执行选项 -> 自定义测试适配器的路径中,按照帮助中的建议,将 NUnitVisualStudioTestAdapter-2.0.0.vsix 插件的目录路径放入。

无论我做什么,它似乎都没有找到或尝试运行它。它只运行 Visual Studio 测试并报告未找到任何测试。我还尝试将测试适配器作为 NuGet 包和工具的路径放入其中,但这也不起作用。

有没有人设法让 NUnit 在 VSTS 中工作并报告测试结果?

我得到的日志是:

2017-02-07T10:59:26.2778725Z ##[section]Starting: Test Assemblies **\*.Unit.Tests.dll;-:**\obj\**
2017-02-07T10:59:26.2798723Z ==============================================================================
2017-02-07T10:59:26.2798723Z Task : Visual Studio Test
2017-02-07T10:59:26.2798723Z Description : Run tests with Visual Studio test runner
2017-02-07T10:59:26.2798723Z Version : 2.0.10
2017-02-07T10:59:26.2798723Z Author : Microsoft Corporation
2017-02-07T10:59:26.2798723Z Help : [More Information](https://go.microsoft.com/fwlink/?LinkId=835764)
2017-02-07T10:59:26.2798723Z ==============================================================================
2017-02-07T10:59:28.6268742Z ##[warning]No test assemblies found matching the pattern: **\*.Unit.Tests.dll;-:**\obj\**.
2017-02-07T10:59:28.6998724Z ##[section]Finishing: Test Assemblies **\*.Unit.Tests.dll;-:**\obj\**

单元测试 DLL 文件称为 App.Web.Unit.Tests.dll。

设置 system.debug = true 后,我得到的日志如下(删除了一些导入语句以适应 30,000 个字符):
2017-02-08T10:44:46.2171630Z ##[section]Starting: Test Assemblies **\*.Unit.Tests.dll;-:**\obj\**
2017-02-08T10:44:46.2251636Z ==============================================================================
2017-02-08T10:44:46.2251636Z Task : Visual Studio Test
2017-02-08T10:44:46.2251636Z Description : Run tests with Visual Studio test runner
2017-02-08T10:44:46.2251636Z Version : 1.0.84
2017-02-08T10:44:46.2251636Z Author : Microsoft Corporation
2017-02-08T10:44:46.2251636Z Help : [More Information](https://go.microsoft.com/fwlink/?LinkId=624539)
2017-02-08T10:44:46.2251636Z ==============================================================================
2017-02-08T10:44:46.2381636Z Preparing task execution handler.
2017-02-08T10:44:52.1286673Z Executing the powershell script: D:\a\_tasks\VSTest_ef087383-ee5e-42c7-9a53-ab56c98420f9\1.0.84\VSTest.ps1
2017-02-08T10:44:52.1296976Z ##[debug]PowerShellHandler.Execute - AddCommand(D:\a\_tasks\VSTest_ef087383-ee5e-42c7-9a53-ab56c98420f9\1.0.84\VSTest.ps1)
2017-02-08T10:44:52.1296976Z ##[debug]PowerShellHandler.Execute - Add inputParameters
2017-02-08T10:44:52.1296976Z ##[debug]PowerShellHandler.Execute - AddParameter(testAssembly=**\*Tests.dll;-:**\obj\**)
2017-02-08T10:44:52.1296976Z ##[debug]PowerShellHandler.Execute - AddParameter(testFiltercriteria=)
2017-02-08T10:44:52.1296976Z ##[debug]PowerShellHandler.Execute - AddParameter(runSettingsFile=D:\a\1\s)
2017-02-08T10:44:52.1296976Z ##[debug]PowerShellHandler.Execute - AddParameter(overrideTestrunParameters=)
2017-02-08T10:44:52.1296976Z ##[debug]PowerShellHandler.Execute - AddParameter(codeCoverageEnabled=true)
2017-02-08T10:44:52.1296976Z ##[debug]PowerShellHandler.Execute - AddParameter(runInParallel=false)
2017-02-08T10:44:52.1296976Z ##[debug]PowerShellHandler.Execute - AddParameter(vstestLocationMethod=version)
2017-02-08T10:44:52.1296976Z ##[debug]PowerShellHandler.Execute - AddParameter(vsTestVersion=latest)
2017-02-08T10:44:52.1296976Z ##[debug]PowerShellHandler.Execute - AddParameter(vstestLocation=)
2017-02-08T10:44:52.1296976Z ##[debug]PowerShellHandler.Execute - AddParameter(pathtoCustomTestAdapters=D:\a\1\s\packages)
2017-02-08T10:44:52.1296976Z ##[debug]PowerShellHandler.Execute - AddParameter(otherConsoleOptions=)
2017-02-08T10:44:52.1296976Z ##[debug]PowerShellHandler.Execute - AddParameter(testRunTitle=)
2017-02-08T10:44:52.1296976Z ##[debug]PowerShellHandler.Execute - AddParameter(platform=any cpu)
2017-02-08T10:44:52.1296976Z ##[debug]PowerShellHandler.Execute - AddParameter(configuration=release)
2017-02-08T10:44:52.1296976Z ##[debug]PowerShellHandler.Execute - AddParameter(publishRunAttachments=true)
2017-02-08T10:44:52.4586977Z ##[debug]PowerShellHandler.Execute - Invoke
2017-02-08T10:44:52.5076979Z ##[debug]Entering script VSTest.ps1
2017-02-08T10:44:52.5096982Z ##[debug]vsTestVersion = latest
2017-02-08T10:44:52.5096982Z ##[debug]testAssembly = **\*Tests.dll;-:**\obj\**
2017-02-08T10:44:52.5096982Z ##[debug]testFiltercriteria =
2017-02-08T10:44:52.5096982Z ##[debug]runSettingsFile = D:\a\1\s
2017-02-08T10:44:52.5096982Z ##[debug]codeCoverageEnabled = true
2017-02-08T10:44:52.5106990Z ##[debug]pathtoCustomTestAdapters = D:\a\1\s\packages
2017-02-08T10:44:52.5106990Z ##[debug]overrideTestrunParameters =
2017-02-08T10:44:52.5106990Z ##[debug]otherConsoleOptions =
2017-02-08T10:44:52.5106990Z ##[debug]testRunTitle =
2017-02-08T10:44:52.5106990Z ##[debug]platform = any cpu
2017-02-08T10:44:52.5106990Z ##[debug]configuration = release
2017-02-08T10:44:52.5106990Z ##[debug]publishRunAttachments = true
2017-02-08T10:44:52.5106990Z ##[debug]vstestLocation =
2017-02-08T10:44:52.5476990Z ##[debug]Loading module from path 'C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\2.111.1\externals\vstshost\Microsoft.TeamFoundation.DistributedTask.Task.Internal\Microsoft.TeamFoundation.DistributedTask.Task.Internal.psd1'.
2017-02-08T10:44:52.5566992Z ##[debug]Loading module from path 'C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\2.111.1\externals\vstshost\Microsoft.TeamFoundation.DistributedTask.Task.Internal\Microsoft.TeamFoundation.DistributedTask.Task.Internal.psm1'.
2017-02-08T10:44:52.5656993Z ##[debug]Loading module from path 'C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\2.111.1\externals\vstshost\Microsoft.TeamFoundation.DistributedTask.Task.LegacySDK.dll'.
2017-02-08T10:44:52.6656999Z ##[debug]Loading module from path 'C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\2.111.1\externals\vstshost\Microsoft.TeamFoundation.DistributedTask.Task.Common\Microsoft.TeamFoundation.DistributedTask.Task.Common.psd1'.
2017-02-08T10:44:52.6727018Z ##[debug]Loading module from path 'C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\2.111.1\externals\vstshost\Microsoft.TeamFoundation.DistributedTask.Task.Common\Microsoft.TeamFoundation.DistributedTask.Task.Common.psm1'.
2017-02-08T10:44:52.7086999Z ##[debug]Loading module from path 'C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\2.111.1\externals\vstshost\Microsoft.TeamFoundation.DistributedTask.Task.TestResults\Microsoft.TeamFoundation.DistributedTask.Task.TestResults.psm1'.
2017-02-08T10:44:52.7336993Z ##[debug]Loading module from path 'C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\2.111.1\externals\vstshost\Microsoft.TeamFoundation.DistributedTask.Task.CodeCoverage\Microsoft.TeamFoundation.DistributedTask.Task.CodeCoverage.psm1'.
2017-02-08T10:44:52.7406994Z ##[debug]Importing cmdlet 'Invoke-ResultPublisher'.
2017-02-08T10:44:52.7416986Z ##[debug]Importing cmdlet 'Publish-TestResults'.
2017-02-08T10:44:52.7416986Z ##[debug]Importing cmdlet 'Add-BuildArtifactLink'.
2017-02-08T10:44:52.7416986Z ##[debug]Importing cmdlet 'Get-MSBuildLocation'.
2017-02-08T10:44:52.7416986Z ##[debug]Importing cmdlet 'Get-ToolPath'.
2017-02-08T10:44:52.7416986Z ##[debug]Importing cmdlet 'Get-VisualStudioPath'.
2017-02-08T10:44:52.7427007Z ##[debug]Importing cmdlet 'Get-VssConnection'.
2017-02-08T10:44:52.7427007Z ##[debug]Importing cmdlet 'Invoke-Ant'.
2017-02-08T10:44:52.7427007Z ##[debug]Importing cmdlet 'Register-XamarinLicense'.
2017-02-08T10:44:52.7427007Z ##[debug]Importing cmdlet 'Remove-Environment'.
2017-02-08T10:44:52.7427007Z ##[debug]Importing cmdlet 'Remove-EnvironmentResources'.
2017-02-08T10:44:52.7427007Z ##[debug]Importing cmdlet 'Complete-EnvironmentOperation'.
2017-02-08T10:44:52.7427007Z ##[debug]Importing cmdlet 'Complete-EnvironmentResourceOperation'.
2017-02-08T10:44:52.7436999Z ##[debug]Importing cmdlet 'Complete-ResourceOperation'.
2017-02-08T10:44:52.7436999Z ##[debug]Importing cmdlet 'Get-Environment'.
2017-02-08T10:44:52.7436999Z ##[debug]Importing cmdlet 'Get-EnvironmentProperty'.
2017-02-08T10:44:52.7436999Z ##[debug]Importing cmdlet 'Get-EnvironmentResources'.
2017-02-08T10:44:52.7436999Z ##[debug]Importing cmdlet 'Get-ExternalIpAddress'.
2017-02-08T10:44:52.7436999Z ##[debug]Importing cmdlet 'Get-ParsedSessionVariables'.
2017-02-08T10:44:52.7436999Z ##[debug]Importing cmdlet 'Add-TaskIssue'.
2017-02-08T10:44:52.7447001Z ##[debug]Importing cmdlet 'Publish-CodeCoverage'.
2017-02-08T10:44:52.7447001Z ##[debug]Exporting cmdlet 'Enable-CodeCoverage'.
2017-02-08T10:44:52.7447001Z ##[debug]Exporting cmdlet 'Publish-CodeCoverage'.
2017-02-08T10:44:52.7447001Z ##[debug]Importing cmdlet 'Enable-CodeCoverage'.
2017-02-08T10:44:52.7447001Z ##[debug]Importing cmdlet 'Publish-CodeCoverage'.
2017-02-08T10:44:52.8017010Z ##[debug]Invoke - Get-TaskVariable cmdlet
2017-02-08T10:44:52.8107020Z ##[debug]Pattern found in solution parameter. Calling Find-Files.
2017-02-08T10:44:52.8107020Z ##[debug]Calling Find-Files with pattern: **\*Tests.dll;-:**\obj\**
2017-02-08T10:44:52.8147008Z ##[debug]FindFiles.FindMatchingFiles(rootFolder = D:\a\1\s, matchPattern = **\*Tests.dll;-:**\obj\**, includeFiles = True, includeFolders = False
2017-02-08T10:44:52.8177007Z ##[debug]FindFiles.GetMatchingItems(includePatterns.Count = 1, excludePatterns.Count = 1, includeFiles = True, includeFolders = False
2017-02-08T10:44:53.4177077Z ##[debug]FindFiles.FindMatchingFiles - Found 0 matches
2017-02-08T10:44:53.4237058Z ##[debug]Found files:
2017-02-08T10:44:53.4467065Z ##[debug]Processed: ##vso[task.logissue type=warning;code=002004;]
2017-02-08T10:44:53.4467065Z
2017-02-08T10:44:53.4467065Z
2017-02-08T10:44:53.4587060Z ##[warning]No test assemblies found matching the pattern: '**\*Tests.dll;-:**\obj\**'.
2017-02-08T10:44:53.4587060Z ##[debug]Processed: ##vso[task.logissue type=warning]No test assemblies found matching the pattern: '**\*Tests.dll;-:**\obj\**'.
2017-02-08T10:44:53.4607060Z ##[debug]Leaving script VSTest.ps1
2017-02-08T10:44:53.4914646Z ##[section]Finishing: Test Assemblies **\*.Unit.Tests.dll;-:**\obj\**

更新:

我已经将 NUnit3TestAdapter 包安装到单元测试项目中。我修改了 VSTS 中的构建步骤:

这是版本 2.*(预览)

搜索模式是:
*测试*.dll
!
\对象**
在高级执行选项中,我将自定义测试适配器的路径设置为 $(Build.SourcesDirectory)\

然后我得到这个调试信息,所以至少它已经找到了测试适配器,如果不是现在的测试:
[command]"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" D:\a\1\s\packages\NUnit3TestAdapter.3.7.0\tools\NUnit3.TestAdapter.dll /EnableCodeCoverage /logger:trx "/TestAdapterPath:\"D:\a\1\s\\\""
Microsoft (R) Test Execution Command Line Tool Version 14.0.25420.1
Copyright (c) Microsoft Corporation. All rights reserved.

Starting test execution, please wait...
Warning: Using Isolation mode to run tests as required by effective Platform:X86 and .Net Framework:Framework35 settings for test run. Use the /inIsolation parameter to suppress this warning.
Information: NUnit Adapter 3.7.0.0: Test execution started

Information: Running all tests in D:\a\1\s\packages\NUnit3TestAdapter.3.7.0\tools\NUnit3.TestAdapter.dll

Information: NUnit failed to load D:\a\1\s\packages\NUnit3TestAdapter.3.7.0\tools\NUnit3.TestAdapter.dll

Information: NUnit Adapter 3.7.0.0: Test execution complete

Warning: No test is available in D:\a\1\s\packages\NUnit3TestAdapter.3.7.0\tools\NUnit3.TestAdapter.dll. Make sure that installed test discoverers & executors, platform & framework version settings are appropriate and try again.

最佳答案

自定义测试适配器的路径必须指向 提取 vsix 或提取的 NuGet 包。

使这项工作最简单的方法是添加 NUnit Test Adapter NuGet package 2.x/3.x到您的单元测试项目。 VsTest 任务应自动检测还原到 NuGet 包目录的测试运行程序:

NuGet restored packages are automatically searched for

确保 nunit.framework 版本和 NUnit 适配器版本匹配。确保 两者 包被添加到您的测试项目中。

关于nunit - 如何在 VSTS 中使用 NUnit?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42086874/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com