为什么 VSTS Build "Visual Studio Test" 步骤找不到我的 NUnit 测试?

Why doesn't VSTS Build "Visual Studio Test" step find my NUnit tests?

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

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

No test is available in D:\a\s\MSFakesExamples\bin\Release\MSFakesExamples.dll D:\a\s\MoqExamples\bin\Release\MoqExamples.dll D:\a\s\NSubstituteExamples\bin\Release\NSubstituteExamples.dll D:\a\s\RhinoMocksExamples\bin\Release\RhinoMocksExamples.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.

我需要更改什么才能让测试 运行 找到并 运行 我的测试?

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

Test frameworks that have a Visual Studio test adapter such as xUnit, NUnit, Chutzpah, etc. can also be run.

我已经确保程序集确实在构建,并且我还利用 Typemock SmartRunner 构建步骤来 运行 测试,它会找到并执行它们(尽管它失败了MS Fakes 程序集,所以我不能只使用它)。

下面是完整的构建步骤配置和 "Visual Studio Test" 步骤的控制台输出。构建过程在 "Hosted 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\s
2018-07-19T18:28:28.6972990Z Run settings file : D:\a\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 Studio17\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" @D:\a\_tempc64f61-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\s\MSFakesExamples\bin\Release\MSFakesExamples.dll"
2018-07-19T18:28:33.5442179Z "D:\a\s\MoqExamples\bin\Release\MoqExamples.dll"
2018-07-19T18:28:33.5442549Z "D:\a\s\NSubstituteExamples\bin\Release\NSubstituteExamples.dll"
2018-07-19T18:28:33.5442909Z "D:\a\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\s\MSFakesExamples\bin\Release\MSFakesExamples.dll D:\a\s\MoqExamples\bin\Release\MoqExamples.dll D:\a\s\NSubstituteExamples\bin\Release\NSubstituteExamples.dll D:\a\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\s\TestResults4c9712-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

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

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