42

TL;博士; 编辑 6:我已经缩小范围并提供了 5 个步骤来重现问题/错误。

  1. 创建一个 VS2017 c# Console App (.Net Full Framework)
  2. 向 Program.cs 添加一个方法并使该类公开:

 

public class Program
{
    static void Main(string[] args)
    {
    }

    public int Add(int a, int b)
    { 
        return a + b;
    }
}
}
  1. 右键单击Add方法并选择创建单元测试:

在此处输入图像描述

  1. 使用这些设置来创建一个带有测试的新单元测试项目:

在此处输入图像描述

  1. 添加单元测试

 

[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.TestAdapterMSTest.TestFramework 我已经完成并引用了两个 V1.18 的html :

  • Microsoft.VisualStudio.TestPlatform.TestFramework
  • Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions

有很多 beta 测试人员报告了同样的问题:

https://developercommunity.visualstudio.com/content/problem/4510/live-unit-testing-doesnt-do-anything-1.html

https://developercommunity.visualstudio.com/content/problem/2737/live-unit-testing-doesnt-do-anything.html

https://developercommunity.visualstudio.com/content/problem/4376/live-unit-testing-doesnt-work.html

https://developercommunity.visualstudio.com/content/problem/2527/live-unit-testing-doesnt-work-for-projects-that-im.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:

根据这个博客: https ://blogs.msdn.microsoft.com/visualstudio/2017/03/09/live-unit-testing-in-visual-studio-2017-enterprise/

问:为什么我在 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报告了这个问题,并会及时通知大家。它正确地没有被报告环境被锁定。

4

7 回答 7

3

更新: MS 说它已在 15.3.2 中修复

https://social.msdn.microsoft.com/Forums/vstudio/en-US/9f5a5c01-052b-4b6a-94c5-70aae9cdf843/vs2017-live-unit-testing-only-minuss?forum=vsunittest


好的,我已经缩小了范围。

当您添加对单元测试项目的 NuGet 引用时,它会添加一个 packages.config并且在某些情况下可能会添加一个 App.Config 文件。

当我添加Oracle.ManagedDataAccess时,将以下内容添加到 App.Config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <!--<configSections>
    <section name="oracle.manageddataaccess.client"
      type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
    </configSections>-->
  <system.data>
    <DbProviderFactories>
      <remove invariant="Oracle.ManagedDataAccess.Client"/>
      <add name="ODP.NET, Managed Driver" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET, Managed Driver"
        type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
    </DbProviderFactories>
  </system.data>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <publisherPolicy apply="no"/>
        <assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral"/>
        <bindingRedirect oldVersion="4.121.0.0 - 4.65535.65535.65535" newVersion="4.122.1.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <oracle.manageddataaccess.client>
    <version number="*">
      <dataSources>
        <dataSource alias="SampleDataSource" descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCL))) "/>
      </dataSources>
    </version>
  </oracle.manageddataaccess.client>
</configuration>

请注意我是如何注释掉<!--<configSections ... configSections>-->的,纯粹是通过消除过程,我发现它的这个特定的 App.Config 标记会导致 Live Unit Testing 失败。

于 2017-09-14T00:37:09.570 回答
2

正如其他人所提到的,这个功能仍然有点错误。我已经相当幸运了,但是只需打开该功能并注意测试资源管理器窗口 - 至少在我的盒子上,它会运行测试,即使代码编辑器的排水沟中有“减号” . 但是,我已经看到该功能正常工作。

我会继续使用该功能,并继续以任何方式向 Microsoft 提供反馈(Visual Studio 菜单栏中应该有一个发送反馈按钮)。

更新:
使用现有项目,我在编辑器的排水沟中根本看不到 UI ......我安装了 15.3.4 版。我在 Live Unit Tests 和 Rebuild 中包含了一个完整的解决方案...我在“输出”窗口中收到此消息:

[11:42:17.584 Info] No supported test adapters are referenced by this solution. If you have a test project, add a NuGet reference to a test adapter corresponding to the test framework used in order to run the tests. If you already have the required NuGet reference in your test project, performing a NuGet restore may resolve the issue.

更新 2:创建一个新项目作为测试用例,并按照您的步骤包含一个添加 configsections 标记的 NuGet 包,我能够重现该问题。希望这不会增加混乱,但是当configsections 标记被注释掉(并且安装了 Oracle 包)时,我只遇到了排除的测试/减号问题。

于 2017-09-16T11:55:18.460 回答
2

我认为该功能很棒,而且效果很好。然而并不是那么新(见:http ://www.ncrunch.net/ )。

它也有一个问题,我刚刚遇到了这个问题。这是非常相似的问题,就像你一样。你有多个单元测试项目吗?如果是,那么您应该检查整个解决方案的 Nuget 包。右键单击解决方案并单击“管理解决方案的 Nuget 包...”检查“合并”选项卡并确保您在以下每个测试项目中安装了相同的版本:

  • MSTest.TestAdapter
  • MSTest.TestFramew

这是错误设置的屏幕截图,这将导致整个 Live 单元测试功能失败。

在此处输入图像描述

将所有项目更新到相同版本后,它应该可以工作。但为了确定:

  • 重启VS
  • 在开始实时单元测试之前:转到您的项目文件夹 .vs\\lut 您可以删除整个 LUT(实时单元测试)文件夹。它可能包含无效的缓存数据。

我希望它有所帮助。

于 2017-11-22T19:48:04.080 回答
2

我在使用 v15.5.6 时遇到了同样的问题。我发现解决方案是转到工具 | 实时单元测试 | 删除持久数据。

于 2018-02-18T12:43:29.953 回答
1

我相信您已经发现了问题,但在我的情况下,它有助于简单地安装 Microsoft.NET.Test.Sdk。确保将其添加到您的测试项目中。我花了几天时间试图解决这个问题,就这么简单。

在此处输入图像描述

于 2021-02-22T12:50:04.113 回答
0

我在一个简单的解决方案中遇到了同样的问题,其中包括一个类库项目和一个测试项目。显然我的测试项目被排除在 Live Unit Testing 之外。包含项目后(右键单击项目> Live Unit Testing > Include)图标正常工作。虽然这为我解决了这个问题,但我真的不清楚在我的测试类中的每一行代码上都有实时测试图标的价值是什么。

于 2018-06-26T09:26:31.323 回答
-1

我遇到了这个确切的问题,并且能够通过更新到 Visual Studio 15.7.3 并选择“测试”>“实时单元测试”>“选项”来解决这个问题 - 然后运行“删除持久数据”。

于 2018-06-08T19:13:07.437 回答