首页 > 解决方案 > 为什么 VSTS 构建“Visual Studio 测试”步骤找不到我的 NUnit 测试?

问题描述

我已经配置了一个 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 实例可以轻松查找和运行测试。该步骤的文档Visual Studio Test说它将运行 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

标签: azure-devopsnunitazure-pipelinesvstest.console.exe

解决方案


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


推荐阅读