TL;博士; 编辑 6:我已经缩小范围并提供了 5 个步骤来重现问题/错误。
- 创建一个 VS2017 c# Console App (.Net Full Framework)
- 向 Program.cs 添加一个方法并使该类公开:
public class Program
{
static void Main(string[] args)
{
}
public int Add(int a, int b)
{
return a + b;
}
}
}
- 右键单击
Add
方法并选择创建单元测试:
- 使用这些设置来创建一个带有测试的新单元测试项目:
- 添加单元测试
[TestMethod()]
public void AddTest()
{
Program p = new Program();
var r = p.Add(1, 2);
Assert.IsTrue(3 == r);
}
- 测试菜单 > 实时单元测试 > 开始
AddTest()
> Live Testing > Include上的上下文菜单
现在将 Add 的+符号更改为-
Live Unit Testing 有效,将 -符号改回+并且 Live Test 通过!
现在添加对 Nuget DLL 的引用(任何人都会这样做)- Live Unit Testing 不再有效!或者干脆关闭解决方案,重新打开它,Live Unit Testing 不再工作!
我已经设置了一个 MSUnitTest v2 项目并开始了 Live Unit Testing。我正在使用 Web Api 2 .Net 项目(完整框架 v4.5.2)。
我到处都看到减号,但没有刻度或十字。
我更改代码的方式与它们在 Visual Studio 2017 中的 Live Unit Testing 视频中所做的相同,时钟出现在减号上,但随后什么也没有……
当我调试它时,单元测试将通过:
当我将鼠标悬停在蓝色减号上时,消息是“被 0 个测试覆盖”
我发现您需要按照https://developercommunity.visualstudio.com/content/problem/5520/live-unit-test-are-only-showing-minuses-using-micr 的MSTest.TestAdapter和MSTest.TestFramework 。我已经完成并引用了两个 V1.18 的html :
- Microsoft.VisualStudio.TestPlatform.TestFramework
- Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions
有很多 beta 测试人员报告了同样的问题:
https://developercommunity.visualstudio.com/content/problem/4376/live-unit-testing-doesnt-work.html
所有帖子都已解决或不会修复。
这个Stackoverflow 用户遇到了 Live Unit Testing 的问题,但它是 Null Exception问题。我在评论中尝试了解决方案以从 Gac 中删除 Microsoft.VisualStudio.QualityTools.UnitTestFramework,当我尝试从 C:\Windows\assembly 卸载时,我被拒绝访问并通过开发人员命令提示符卸载:
GacUtil /u Microsoft.VisualStudio.QualityTools.UnitTestFramework
结果是:
程序集:Microsoft.VisualStudio.QualityTools.UnitTestFramework,版本=10.0.0.0,文化=中性,PublicKeyToken=b03f5f7f11d50a3a,处理器架构=MSIL 无法卸载:一个或多个应用程序需要程序集
有人可以帮我让 Live Unit Testing 工作吗?
编辑1:
在 VS > Tools > Options > Live Unit testing 中,我将日志记录改为 Verbose。
查看输出我看到一个警告:
[15:48:26.521 详细] - TestDriver - TestDiscoverer 日志消息:警告 - 配置系统初始化失败
在这几个答案之后,我仍然无法摆脱“配置系统无法初始化” - 不确定这是否是红鲱鱼,这是我迄今为止发现的唯一线索......
编辑2:
我以管理员身份运行 VS2017 并摆脱了“配置系统无法初始化”。不幸的是,以管理员身份运行并没有什么不同,它仍然不起作用,但不会因任何异常而失败。
这是详细日志。有趣的是,“准备开始测试发现”看起来像是找到了我包含的 x86 测试。
但是,它显然无法发现测试;“发现 0 个测试”
[16:52:55.110 Verbose] - Aggregator - Calculating the set of tests that cover 1 files
[16:52:55.110 Verbose] - Aggregator - [Workflow 4] Sending TestRequestEvent with 6 assemblies and 0 tests
[16:52:55.110 Verbose] - TestDriver - [Workflow 4] Received TestRequestEvent
[16:52:55.110 Verbose] - TestDriver - [Workflow 4] Preparing to start test discovery (X64: 0, X86: 1).
[16:52:55.110 Verbose] - TestDriver - [Workflow 4] Start discovering tests from group 0, which contains 1 assemblies.
[16:52:55.599 Verbose] - TestDriver - [Workflow 4] Finished discovering test from group 0.
[16:52:55.599 Verbose] - TestDriver - [Workflow 4] Discovered 0 tests from XYZ.API.ClientService\bin\Debug\XYZ.API.ClientService.dll, updating cached data.
[16:52:55.599 Verbose] - TestDriver - [Workflow 4] Notify Aggregator about completion of test run. (Passed: 0, Failed: 0, Run succeeded: True)
[16:52:55.599 Verbose] - Aggregator - [Workflow 4] Received TestResponseEvent (TestRunCompleted)
[16:52:55.599 Verbose] - Aggregator - [Workflow 4] Coverage data for 0 tests was received during this workflow
[16:52:55.600 Verbose] - BuildManager - Allow to send a single build event.
[16:52:55.599 Verbose] - Aggregator - Starting coverage aggregation cycle - work list has 3 methods
[16:52:55.599 Verbose] - Aggregator - Finished coverage aggregation cycle - work list had 3 methods of which 3 methods were defined in 2 open files
[16:52:55.600 Verbose] - BuildManager - Interrupting build queue -> no new assemblies.
[16:52:55.600 Verbose] - StatusMargin - Received file coverage result
[16:52:55.599 Verbose] - Aggregator - Sending FileCoverageResult for 'C:\XYZProjectCollection\XYZ\XYZ.API.ClientService\Repositories\ValueRepository.cs - C:\XYZProjectCollection\Lincoln\XYZ.API.ClientService\XYZ.API.MiscService.csproj'
[16:52:55.599 Verbose] - Aggregator - [Workflow 4] Sending TestRunCompletedEvent
编辑3:
我今天查看了 ProcessMonitor 跟踪.. 没有什么特别突出的,我可能错过了一些东西,但我开始觉得这是一个错误而不是配置问题。
我在一个真正锁定的环境中工作,所以可能是在 vs2017 安装期间某些东西被阻止了。我知道 Unity3D 域没有被列入下载白名单。尽管安装了所有核心 Visual Studio Microsoft 的东西。我开始用尽诊断故障排除策略。任何想法都非常欢迎!
编辑4:
今天早上我决定Microsoft.VisualStudio.QualityTools.UnitTestFramework
从 GAC 中删除 DLL。我按照以下说明进行操作以克服 Access Denied:
这导致找到潜在的根本原因之一。我开始看到 Live Unit Testing Logging 输出:
[09:44:59.053 Verbose] - BuildManager - C:\Program Files x86\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(3245,5): error MSB3491: Could not write lines to file "C:\XYZProjectCollection\Lincoln\.vs\XYZ.API\18528\i\XYZ.API.MiscService\Debug\CoreCompileInputs.cache". Access to the path 'C:\XYZProjectCollection\Lincoln\.vs\XYZ.API\18528\i\XYZ.API.MiscService\Debug\CoreCompileInputs.cache' is denied.
[09:44:59.053 Verbose] - BuildManager - C:\Program Files x86\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(4874,5): error MSB3491: Could not write lines to file "C:\XYZProjectCollection\Lincoln\.vs\XYZ.API\18528\i\XYZ.API.MiscService\Debug\XYZ.API.MiscService.csproj.FileListAbsolute.txt". Access to the path 'C:\XYZProjectCollection\Lincoln\.vs\XYZ.API\18528\i\XYZ.API.MiscService\Debug\XYZ.API.MiscService.csproj.FileListAbsolute.txt' is denied.
我允许自己访问所有这些目录,只是为了排除任何权限问题:
这仍然不起作用,但是似乎我越来越接近了,因为实时单元测试需要更长的时间才能不起作用(即出现在减号顶部的时钟需要更长的时间来处理)。
然后我再次尝试了 ProcMon,它显示了一些有趣的日志,但没有确凿证据。
这是当前的详细日志:
[10:22:07.363 Info] - BuildManager - Build completed (succeeded).
[10:22:07.363 Verbose] - BuildManager - Interrupting build queue -> switching 'build' and 'test' directories.
[10:22:07.363 Verbose] - BuildManager - New 'test' directory: C:\XYZProjectCollection\Lincoln\.vs\XYZ.API\18528\1\
[10:22:07.363 Verbose] - BuildManager - New 'build' directory: C:\XYZProjectCollection\Lincoln\.vs\XYZ.API\18528\0\
[10:22:07.363 Verbose] - Aggregator - [Workflow 4] Received BuildEvent.
[10:22:07.363 Verbose] - Aggregator - assembly: C:\XYZProjectCollection\Lincoln\.vs\XYZ.API\18528\t\XYZ.API.Tests\bin\Debug\XYZ.API.Tests.dll
[10:22:07.363 Verbose] - Aggregator - assembly: C:\XYZProjectCollection\Lincoln\.vs\XYZ.API\18528\t\XYZ.API.AccountClientService\bin\Debug\XYZ.API.AccountClientService.dll
[10:22:07.363 Verbose] - Aggregator - assembly: C:\XYZProjectCollection\Lincoln\.vs\XYZ.API\18528\t\XYZ.API\bin\XYZ.API.dll
[10:22:07.363 Verbose] - Aggregator - assembly: C:\XYZProjectCollection\Lincoln\.vs\XYZ.API\18528\t\XYZ.API.Helpers\bin\Debug\XYZ.API.Global.dll
[10:22:07.363 Verbose] - Aggregator - assembly: C:\XYZProjectCollection\Lincoln\.vs\XYZ.API\18528\t\XYZ.API.MiscService\bin\Debug\XYZ.API.MiscService.dll
[10:22:07.363 Verbose] - Aggregator - file: 'C:\XYZProjectCollection\Lincoln\XYZ.API.MiscService\Repositories\ValueRepository.cs - C:\XYZProjectCollection\Lincoln\XYZ.API.MiscService\XYZ.API.MiscService.csproj'
[10:22:07.363 Verbose] - Aggregator - Skip reading spans for assembly C:\XYZProjectCollection\Lincoln\.vs\XYZ.API\18528\t\XYZ.API.Tests\bin\Debug\XYZ.API.Tests.dll with MVID c96c0f4b-b21e-47be-a71e-97ebf8a3d493 since we already have this information from a previous build
[10:22:07.363 Verbose] - Aggregator - Skip reading spans for assembly C:\XYZProjectCollection\Lincoln\.vs\XYZ.API\18528\t\XYZ.API.AccountClientService\bin\Debug\XYZ.API.AccountClientService.dll with MVID 6772f896-04ab-4804-bb18-3ed2c7aeb9b9 since we already have this information from a previous build
[10:22:07.363 Verbose] - Aggregator - Skip reading spans for assembly C:\XYZProjectCollection\Lincoln\.vs\XYZ.API\18528\t\XYZ.API\bin\XYZ.API.dll with MVID 9c862440-c16a-4efe-8574-76e8c1453c4d since we already have this information from a previous build
[10:22:07.363 Verbose] - Aggregator - Skip reading spans for assembly C:\XYZProjectCollection\Lincoln\.vs\XYZ.API\18528\t\XYZ.API.Helpers\bin\Debug\XYZ.API.Global.dll with MVID a8899d5d-4730-46bf-b4f2-3c2b1b75b0b1 since we already have this information from a previous build
[10:22:07.363 Verbose] - Aggregator - Removing MVID f337ca44-aae6-42ca-8df5-3776ff962372 for project C:\XYZProjectCollection\Lincoln\XYZ.API.MiscService\XYZ.API.MiscService.csproj from the file span cache
[10:22:07.363 Verbose] - Aggregator - Adding MVID 8e944276-0eec-43f4-aff3-07e40f8611dc for project C:\XYZProjectCollection\Lincoln\XYZ.API.MiscService\XYZ.API.MiscService.csproj to the file span cache
[10:22:07.363 Verbose] - Aggregator - Calculating the set of tests that cover 0 files
[10:22:07.363 Verbose] - Aggregator - Reading spans for assembly C:\XYZProjectCollection\Lincoln\.vs\XYZ.API\18528\t\XYZ.API.MiscService\bin\Debug\XYZ.API.MiscService.dll with MVID 8e944276-0eec-43f4-aff3-07e40f8611dc
[10:22:07.363 Verbose] - Aggregator - Adding 3 methods from 'C:\XYZProjectCollection\Lincoln\XYZ.API.MiscService\Repositories\ValueRepository.cs - C:\XYZProjectCollection\Lincoln\XYZ.API.MiscService\XYZ.API.MiscService.csproj' to the coverage aggregation work list
[10:22:07.363 Verbose] - Aggregator - Calculating the set of tests that cover 1 files
[10:22:07.363 Verbose] - Aggregator - [Workflow 4] Sending TestRequestEvent with 5 assemblies and 0 tests
[10:22:07.363 Verbose] - TestDriver - [Workflow 4] Received TestRequestEvent
[10:22:07.363 Verbose] - TestDriver - [Workflow 4] Preparing to start test discovery (X64: 0, X86: 1).
[10:22:07.363 Verbose] - TestDriver - [Workflow 4] Start discovering tests from group 0, which contains 1 assemblies.
[10:22:07.834 Verbose] - TestDriver - [Workflow 4] Finished discovering test from group 0.
[10:22:07.834 Verbose] - TestDriver - [Workflow 4] Discovered 0 tests from XYZ.API.MiscService\bin\Debug\XYZ.API.MiscService.dll, updating cached data.
[10:22:07.834 Verbose] - TestDriver - [Workflow 4] Notify Aggregator about completion of test run. (Passed: 0, Failed: 0, Run succeeded: True)
[10:22:07.834 Verbose] - Aggregator - [Workflow 4] Received TestResponseEvent (TestRunCompleted)
[10:22:07.834 Verbose] - Aggregator - [Workflow 4] Coverage data for 0 tests was received during this workflow
[10:22:07.834 Verbose] - Aggregator - Starting coverage aggregation cycle - work list has 3 methods
[10:22:07.834 Verbose] - Aggregator - Finished coverage aggregation cycle - work list had 3 methods of which 3 methods were defined in 5 open files
[10:22:07.834 Verbose] - BuildManager - Allow to send a single build event.
[10:22:07.834 Verbose] - BuildManager - Interrupting build queue -> no new assemblies.
[10:22:07.834 Verbose] - Aggregator - Sending FileCoverageResult for 'C:\XYZProjectCollection\Lincoln\XYZ.API.MiscService\Repositories\ValueRepository.cs - C:\XYZProjectCollection\Lincoln\XYZ.API.MiscService\XYZ.API.MiscService.csproj'
[10:22:07.834 Verbose] - Aggregator - [Workflow 4] Sending TestRunCompletedEvent
[10:22:07.850 Verbose] - StatusMargin - Received file coverage result
编辑5:
问:为什么我在 Live Test Set 中包含或排除测试后没有任何反应?
答:这是一个已知问题,我们无法在 Visual Studio 2017 版本 15.0 中修复。它现在已在 Visual Studio 2017 版本 15.2 中修复。
原来我有 Visual Studio/15.0.0 +26228.9。升级到 Visual Studio 2017 (v15.2)并不能解决问题。
我已经向https://developercommunity.visualstudio.com报告了这个问题,并会及时通知大家。它正确地没有被报告环境被锁定。