如何在 VSTS 中使用 NUnit?

2024-01-08

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

无论我做什么,它似乎都没有找到或尝试运行它。它仅运行 Visual Studio Test 并报告未找到测试。我还尝试将测试适配器作为 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\**

UPDATE:

我已将 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 测试适配器 NuGet 包 2.x https://www.nuget.org/packages/NUnitTestAdapter//3.x https://www.nuget.org/packages/NUnit3TestAdapter/到您的单元测试项目。 VsTest 任务应自动检测恢复到 NuGet 包目录的测试运行程序:

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 VSTS 中使用 NUnit? 的相关文章

随机推荐

  • Qt宏关键字导致名称冲突

    我正在为我的 Qt 项目构建 NCurses 界面 我想使用 CDK 但我认为signals该结构的成员与 Qt 发生冲突signals关键词 usr include linux cdk h 411 error expected unqua
  • SQL - 如果行数大于则插入

    我创建了一个 SQL 查询 该查询将从 Oracle 链接服务器返回行 例如 该查询工作正常 将返回 40 行 我希望仅当返回的行数大于 40 时才将结果插入到表中 我的想法是 我可以创建一个触发器来发送一封电子邮件 告知该号码已被泄露 D
  • 从 C# 调用包含函数指针的 DLL 函数

    我有一个用 C 编写的 DLL 其中包含导出函数 该函数具有用作回调函数的函数指针 C DllExport unsigned int DllFunctionPointer unsigned int i unsigned int TimesT
  • Phantomjs Function.prototype.bind

    对我知道那个 Phantomjs 不支持函数绑定 但也许我可以用别的东西 或者说page open不使用bind 看起来还可以 但是有些网站 返回错误 TypeError undefined is not a function evalua
  • Windows 上的 Python - 如何等待多个子进程?

    如何在 Windows 上的 Python 中等待多个子进程 而不需要主动等待 轮询 像这样的东西almost对我有用 proc1 subprocess Popen python mytest py proc2 subprocess Pop
  • 如何获取传递给函数的变量的原始变量名[重复]

    这个问题在这里已经有答案了 是否可以获取传递给函数的变量的原始变量名 例如 foobar foo def func var print var origname So that func foobar Returns gt gt fooba
  • 警报管理器 2 次

    我有一个BroadcastReceiver called AlarmReceiver that Toasts 警报工作了 我正在尝试设置重复PendingIntent引起AlarmReceiver5 45 和 17 30 但在启动应用程序几
  • grails:如何更改编译的 GSP(gsp*.class 文件)?

    我在 weblogic 中使用 grails 需要更改展开的部署文件夹中的类文件 但这个类实际上是一个gsp编译的文件 那么 问题是 GSP 文件 class 在战争中留在哪里 注意 我正在使用外部 GSP 设置grails gsp vie
  • Google 图表 API JSON 无效

    以下代码返回 Google 图表的 json public static DataTable generateDataTable Create a data table DataTable data new DataTable ArrayL
  • 使用本地化日期进行 Django 查询

    在我的表单中 我有一个名为 booking date 的 DateField 它是使用 AdminDateWidget 呈现的 booking date字段的内容需要国际化 当我想像这样使用字段的值时 就会出现问题 booking Book
  • 访问或获取静态类中的 Autofac Container

    我需要在静态类中获取或访问我的 IoC 容器 这是我的 简化的 场景 我在 Startup 类中注册 ASP net Web Api 的依赖项 而且我也为 MVC 或 WCF 执行此操作 我有一个 DependecyResolver 项目
  • 如何从可变大小的字符串中获取所需的字符?

    我需要提取附加到该单词的所需字符串 例如 pot 1 Sam pot 22 Daniel pot 444 Jack pot 5434 Bill 我需要从上面的字符串中获取名称 即萨姆 丹尼尔 杰克和比尔 问题是 如果我使用子字符串 由于数字
  • git ls-带日期的文件?

    在 GitHub 上 每个文件夹页面上都有这个很好的功能 它列出了文件名以及上次提交该文件的时间 这类似于ls l命令 有没有办法从命令行模仿这种行为 就像是 git ls files l 基于sjas 回答 https stackover
  • mySQL 专家 - 需要“相交”方面的帮助

    我知道 mySQL 5 x 不支持 INTERSECT 但这似乎正是我所需要的 表 A 产品 p id 表 B Prod cats cat id 类别信息 名称 描述等 表 C prod 2cats p id cat id 多对多 prod
  • Android:将父状态传播到子视图

    我遇到了一些我基本上不知道如何解决的问题 我有一个 LinearLayout 里面有一些子组件 如 ImageView TextView 等 可以在下面的 xml 中看到一个示例
  • 为什么我的页眉周围有空白且没有颜色?

    我试图填满整个
  • bash 命令输出作为参数

    假设命令alpha产生这个输出 a b c d 如果我运行命令 beta alpha then beta将使用四个参数执行 a b c and d 但是如果我运行命令 beta alpha then beta将使用一个参数执行 a b c
  • UIWebView 和 Safari 比较

    UIWebView 是否使用与 Mobile Safari 相同的 JavaScript 引擎 另外 UIWebView 是否像 Mobile Safari 一样支持所有 HTML5 功能 我特别关心 Web SQL 和 Web Worke
  • Android 短划线/虚线问题?

    当我使用时Android 虚线 its 在小屏幕上运行良好 but 不适用于 Samsung S3 设备及更高版本 截图 And 可绘制 dashline xml
  • 如何在 VSTS 中使用 NUnit?

    我正在尝试在 Visual Studio Team System 中使用 NUnit 3 但他们似乎让这变得非常困难 我已在构建过程和高级执行选项中添加了测试程序集步骤 gt 自定义测试适配器的路径 我已按照帮助中的建议放入 NUnitVi