【问题标题】:Why doesn't VSTS Build "Visual Studio Test" step find my NUnit tests?为什么 VSTS 构建“Visual Studio 测试”步骤找不到我的 NUnit 测试?
【发布时间】:2018-07-20 05:41:09
【问题描述】:

我已经配置了一个 VSTS 构建作业,以从 GitHub 构建我的 MockingFrameworkExamples .NET 4.7.1 (C#) 解决方案。该解决方案包括五个带有 NUnit v3.10 单元测试的程序集。

我在构建定义中包含了一个Visual Studio Test 步骤,但是当它运行时,控制台输出显示测试程序集中没有可用的测试:

D:\a\1\s\MSFakesExamples\bin\Release\MSFakesExamples.dll D:\a\1\s\MoqExamples\bin\Release\MoqExamples.dll D:\a\1 中没有可用的测试\s\NSubstituteExamples\bin\Release\NSubstituteExamples.dll D:\a\1\s\RhinoMocksExamples\bin\Release\RhinoMocksExamples.dll。确保测试发现者和执行者已注册并且平台和框架版本设置正确,然后重试。

我需要进行哪些更改才能让测试运行程序找到并运行我的测试?

我的本​​地 Visual Studio 2017 实例可以轻松找到和运行测试。 documentation for the Visual Studio Test step 表示它将运行 NUnit 测试:

也可以运行具有 Visual Studio 测试适配器的测试框架,例如 xUnit、NUnit、Chutzpah 等。

我已确定程序集实际上正在构建,并且我还利用Typemock SmartRunner 构建步骤来运行测试,该测试会找到并执行它们(不过,它因 MS Fakes 程序集而失败,所以我可以'不要只是使用它)。

以下是“Visual Studio 测试”步骤的完整构建步骤配置和控制台输出。构建过程配置为在“托管 VS2017”代理上运行。


2018-07-19T18:28:28.1197107Z ##[section]Starting: VsTest - testAssemblies
2018-07-19T18:28:28.1205564Z ==============================================================================
2018-07-19T18:28:28.1205798Z Task         : Visual Studio Test
2018-07-19T18:28:28.1206209Z Description  : Run unit and functional tests (Selenium, Appium, Coded UI test, etc.) using the Visual Studio Test runner. Test frameworks that have a Visual Studio test adapter such as xUnit, NUnit, Chutzpah, etc. can also be run. Tests can be distributed on multiple agents using this task (version 2).
2018-07-19T18:28:28.1206596Z Version      : 2.136.10
2018-07-19T18:28:28.1206775Z Author       : Microsoft Corporation
2018-07-19T18:28:28.1207003Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=835764)
2018-07-19T18:28:28.1207231Z ==============================================================================
2018-07-19T18:28:28.6970694Z Run the tests locally using vstest.console.exe
2018-07-19T18:28:28.6971006Z ========================================================
2018-07-19T18:28:28.6971725Z Test selector : Test assemblies
2018-07-19T18:28:28.6972103Z Test assemblies : **\release\*examples*.dll,!**\release\typemock*examples*.dll,!**\obj\**
2018-07-19T18:28:28.6972430Z Test filter criteria : null
2018-07-19T18:28:28.6972706Z Search folder : D:\a\1\s
2018-07-19T18:28:28.6972990Z Run settings file : D:\a\1\s
2018-07-19T18:28:28.6973481Z Run in parallel : false
2018-07-19T18:28:28.6973748Z Run in isolation : false
2018-07-19T18:28:28.6975710Z Path to custom adapters : null
2018-07-19T18:28:28.6975982Z Other console options : null
2018-07-19T18:28:28.6976254Z Code coverage enabled : true
2018-07-19T18:28:28.6976788Z Rerun failed tests: false
2018-07-19T18:28:28.6977166Z VisualStudio version selected for test execution : latest
2018-07-19T18:28:29.7035629Z ========================================================
2018-07-19T18:28:30.0191054Z [command]"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" @D:\a\_temp\88c64f61-8b81-11e8-a282-258e7155540f.txt
2018-07-19T18:28:33.5193511Z Microsoft (R) Test Execution Command Line Tool Version 15.7.2
2018-07-19T18:28:33.5198868Z Copyright (c) Microsoft Corporation.  All rights reserved.
2018-07-19T18:28:33.5199025Z 
2018-07-19T18:28:33.5440200Z vstest.console.exe 
2018-07-19T18:28:33.5441525Z "D:\a\1\s\MSFakesExamples\bin\Release\MSFakesExamples.dll"
2018-07-19T18:28:33.5442179Z "D:\a\1\s\MoqExamples\bin\Release\MoqExamples.dll"
2018-07-19T18:28:33.5442549Z "D:\a\1\s\NSubstituteExamples\bin\Release\NSubstituteExamples.dll"
2018-07-19T18:28:33.5442909Z "D:\a\1\s\RhinoMocksExamples\bin\Release\RhinoMocksExamples.dll"
2018-07-19T18:28:33.5443312Z /EnableCodeCoverage
2018-07-19T18:28:33.5443575Z /logger:"trx"
2018-07-19T18:28:35.6891585Z Starting test execution, please wait...
2018-07-19T18:28:42.3946126Z Microsoft (R) Coverage Collection Tool Version 15.0.30319.1
2018-07-19T18:28:42.3947458Z 
2018-07-19T18:28:42.3947721Z 
2018-07-19T18:28:42.3948539Z Copyright (c) Microsoft Corporation.  All rights reserved.
2018-07-19T18:28:42.3949162Z 
2018-07-19T18:28:42.3949300Z 
2018-07-19T18:28:42.3949487Z 
2018-07-19T18:28:42.3949624Z 
2018-07-19T18:28:42.6811429Z 2.7184
2018-07-19T18:28:53.8206723Z No test is available in D:\a\1\s\MSFakesExamples\bin\Release\MSFakesExamples.dll D:\a\1\s\MoqExamples\bin\Release\MoqExamples.dll D:\a\1\s\NSubstituteExamples\bin\Release\NSubstituteExamples.dll D:\a\1\s\RhinoMocksExamples\bin\Release\RhinoMocksExamples.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
2018-07-19T18:28:53.9442220Z Microsoft (R) Coverage Collection Tool Version 15.0.30319.1
2018-07-19T18:28:53.9443798Z 
2018-07-19T18:28:53.9445199Z 
2018-07-19T18:28:53.9465185Z Copyright (c) Microsoft Corporation.  All rights reserved.
2018-07-19T18:28:53.9465983Z 
2018-07-19T18:28:53.9466184Z 
2018-07-19T18:28:53.9466360Z 
2018-07-19T18:28:53.9466554Z 
2018-07-19T18:28:54.6483114Z 
2018-07-19T18:28:54.6491201Z Attachments:
2018-07-19T18:28:54.6491635Z   D:\a\1\s\TestResults\324c9712-62bd-4959-b3b6-40bebf7c05ec\VssAdministrator_factoryvm-az243 2018-07-19 18_28_41.coverage
2018-07-19T18:28:54.6491944Z 
2018-07-19T18:28:54.6574103Z Additionally, path to test adapters can be specified using /TestAdapterPath command. Example  /TestAdapterPath:<pathToCustomAdapters>.
2018-07-19T18:28:54.6717566Z ##[warning]No results found to publish.
2018-07-19T18:28:54.7119869Z ##[section]Finishing: VsTest - testAssemblies

【问题讨论】:

  • 我更新了所有的 nuget 包,然后它工作了......

标签: azure-devops nunit azure-pipelines vstest.console.exe


【解决方案1】:

事实证明,我必须将每个单元测试程序集的 NuGet 引用添加到 NUnit3TestAdapter NuGet 包中才能正常工作。无需进行其他配置更改。

【讨论】:

  • 这是正确且推荐的方法。它应该只适用于具有该引用的一个测试项目,但这将在以后更改。我在博文here 中对此进行了详细说明。所以你做得很好,也应该是面向未来的:-)
【解决方案2】:

您需要使用/TestAdapterPath 指定NUnit 适配器的路径。

【讨论】:

  • 如何确定 Hosted VS2017 代理上的路径?
  • 啊...我的假设是您通过使用 NUnit 适配器包将它放在它所在的位置。某些版本会导致适配器被复制到输出目录,因此不需要进一步的操作。其他人没有,所以你必须指定路径。
  • AFAIK,您不能依赖安装了 NUnit 适配器的任何托管环境。
猜你喜欢
  • 2017-01-14
  • 1970-01-01
  • 1970-01-01
  • 2012-11-12
  • 1970-01-01
  • 1970-01-01
  • 2018-10-28
  • 2018-08-04
  • 1970-01-01
相关资源
最近更新 更多