VS2017实时单元测试 - 仅减去 - 不起作用

Jer*_*son 41 .net c# unit-testing visual-studio-2017 live-unit-tests

TL; DR; 编辑6:我缩小了它并提供了5个步骤来重现问题/错误.

  1. 创建VS2017 c#控制台应用程序(.Net完整框架)
  2. 将方法添加到Program.cs并使该类公开:

 

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

    public int Add(int a, int b)
    { 
        return a + b;
    }
}
}
Run Code Online (Sandbox Code Playgroud)
  1. 右键单击AddMethod并选择Create Unit Test:

在此输入图像描述

  1. 使用这些设置可以使用测试创建新的单元测试项目:

在此输入图像描述

  1. 添加单元测试

 

[TestMethod()]
public void AddTest()
{
    Program p = new Program();
    var r = p.Add(1, 2);

    Assert.IsTrue(3 == r);
}
Run Code Online (Sandbox Code Playgroud)
  • 测试菜单>实时单元测试>开始
  • AddTest()> Live Testing> Include上的上下文菜单

现在将Add的+符号更改为-

Live Unit Testing工作,将-符号改 回+,Live Test通过!!

现在添加对Nuget DLL的引用(任何人都可以) - 实时单元测试不再有效!或者只需关闭解决方案,重新打开它,Live Unit Testing就不再有效了!


我已经设置了一个MSUnitTest v2项目并启动了Live Unit Testing.我正在使用Web Api 2 .Net项目(Full Framework v4.5.2).

我看到Minus标志到处都是,但没有Tick或十字架.

我改变代码的方式与在Visual Studio 2017视频中的实时单元测试中的代码相同,时钟显示在减号上但没有任何内容......

在此输入图像描述

单调测试将在我调试时通过:

在此输入图像描述

当我将鼠标悬停在蓝色减号上时,消息为"由0测试覆盖"

我发现你需要MSTest.TestAdapterMSTest.TestFramework,按照https://developercommunity.visualstudio.com/content/problem/5520/live-unit-test-are-only-showing-minuses-using-micr.我已经完成的HTML并且引用了V1.18:

  • 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
Run Code Online (Sandbox Code Playgroud)

结果是:

程序集:Microsoft.VisualStudio.QualityTools.UnitTestFramework,Version = 10.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a,processorArchitecture = MSIL无法卸载:一个或多个应用程序需要汇编

有人可以帮助我让Live Unit Testing工作吗?

编辑1:

在VS>工具>选项>实时单元测试中,我将日志记录转换为详细信息.

看看输出,我看到一个警告:

[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  
Run Code Online (Sandbox Code Playgroud)

编辑3:

我今天看了一下ProcessMonitor的痕迹......没有什么真正脱颖而出,我可能错过了一些东西,但我开始觉得这是一个bug而不是配置问题.

我正在一个非常锁定的环境中工作,因此在vs2017安装期间可能会阻止某些内容.我知道Unity3D域名没有下载白名单.虽然安装了所有核心Visual Studio Microsoft内容.我开始用完诊断故障排除策略了.任何想法都非常欢迎!

编辑4:

今天早上我决定Microsoft.VisualStudio.QualityTools.UnitTestFramework从GAC中删除DLL.我遵循这些说明来克服拒绝访问:

在此输入图像描述

这导致找到潜在的根本原因之一.我开始看到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.
Run Code Online (Sandbox Code Playgroud)

我允许所有这些目录,只是为了排除任何权限问题:

在此输入图像描述

这仍然不能正常工作,但它似乎我越来越近的直播单元测试正在长一点工作(即出现负的取顶更长的时间来处理时钟).

然后我再次尝试了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
Run Code Online (Sandbox Code Playgroud)

编辑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)DOES NOT解决问题.

我已将此问题报告给https://developercommunity.visualstudio.com,并会将所有人发布.它正确地没有报告环境被锁定.

Jer*_*son 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>
Run Code Online (Sandbox Code Playgroud)

请注意我如何注释掉<!--<configSections ... configSections>-->,纯粹通过排除过程,我发现它的这个特定 App.Config 标记导致实时单元测试失败。