只有减号

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

  • 创建一个VS2017 c#控制台应用程序(.Net完整框架)
  • 向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的+符号更改为-

    实时单元测试工作,将-符号更改为+ ,并且实时测试通过!

    现在添加对Nuget DLL的引用(任何人都会这样做) - Live单元测试不再有效! 或者简单地关闭解决方案,重新打开它并且实时单元测试不再有效!


    我已经建立了一个MSUnitTest v2项目并开始了Live Unit Testing。 我正在使用Web Api 2 .Net项目(Full Framework v4.5.2)。

    我看到处处都有减号迹象,但没有勾号或十字。

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

    在这里输入图像描述

    我在调试时会通过单元测试:

    在这里输入图像描述

    当我将鼠标悬停在蓝色减号的上方时,消息为“被0测试覆盖”

    我发现你需要MSTest.TestAdapterMSTest.TestFramework按照https://developercommunity.visualstudio.com/content/problem/5520/live-unit-test-are-only-showing-minuses-using-micr。我已经完成并参考了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单元测试中遇到了一个问题,但是它的一个空异常问题。 当我试图从C: Windows assembly卸载时,我尝试了注释中的解决方案以从Gac中删除Microsoft.VisualStudio.QualityTools.UnitTestFramework。我通过开发人员命令提示符拒绝了访问并卸载:

    GacUtil /u Microsoft.VisualStudio.QualityTools.UnitTestFramework
    

    结果是:

    程序集:Microsoft.VisualStudio.QualityTools.UnitTestFramework,版本= 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.ClientServicebinDebugXYZ.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:XYZProjectCollectionXYZXYZ.API.ClientServiceRepositoriesValueRepository.cs - C:XYZProjectCollectionLincolnXYZ.API.ClientServiceXYZ.API.MiscService.csproj'
    [16:52:55.599 Verbose] - Aggregator - [Workflow 4] Sending TestRunCompletedEvent  
    

    编辑3:

    我今天通过ProcessMonitor跟踪了一下。没有什么真正突出的,我可能错过了一些东西,但我开始觉得这是一个错误而不是配置问题。

    我正在一个非常锁定的环境中工作,因此可能会在vs2017安装期间阻塞某些东西。 我知道Unity3D域名未被列入下载列表。 尽管安装了所有核心的Visual Studio Microsoft东西。 我开始用尽诊断故障排除策略。 任何想法非常欢迎!

    编辑4:

    今天早上,我决定摆脱GAC的Microsoft.VisualStudio.QualityTools.UnitTestFramework DLL。 我按照这些说明来做,以克服拒绝访问:

    在这里输入图像描述

    这导致找到了一个潜在的根源。 我开始看到Live Unit Testing Logging输出:

    [09:44:59.053 Verbose] - BuildManager - C:Program Files x86Microsoft Visual Studio2017EnterpriseMSBuild15.0BinMicrosoft.Common.CurrentVersion.targets(3245,5): error MSB3491: Could not write lines to file "C:XYZProjectCollectionLincoln.vsXYZ.API18528iXYZ.API.MiscServiceDebugCoreCompileInputs.cache". Access to the path 'C:XYZProjectCollectionLincoln.vsXYZ.API18528iXYZ.API.MiscServiceDebugCoreCompileInputs.cache' is denied.   
    [09:44:59.053 Verbose] - BuildManager - C:Program Files x86Microsoft Visual Studio2017EnterpriseMSBuild15.0BinMicrosoft.Common.CurrentVersion.targets(4874,5): error MSB3491: Could not write lines to file "C:XYZProjectCollectionLincoln.vsXYZ.API18528iXYZ.API.MiscServiceDebugXYZ.API.MiscService.csproj.FileListAbsolute.txt". Access to the path 'C:XYZProjectCollectionLincoln.vsXYZ.API18528iXYZ.API.MiscServiceDebugXYZ.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:XYZProjectCollectionLincoln.vsXYZ.API185281
    [10:22:07.363 Verbose] - BuildManager - New 'build' directory: C:XYZProjectCollectionLincoln.vsXYZ.API18528
    [10:22:07.363 Verbose] - Aggregator - [Workflow 4] Received BuildEvent.
    [10:22:07.363 Verbose] - Aggregator - assembly: C:XYZProjectCollectionLincoln.vsXYZ.API18528tXYZ.API.TestsbinDebugXYZ.API.Tests.dll
    [10:22:07.363 Verbose] - Aggregator - assembly: C:XYZProjectCollectionLincoln.vsXYZ.API18528tXYZ.API.AccountClientServicebinDebugXYZ.API.AccountClientService.dll
    [10:22:07.363 Verbose] - Aggregator - assembly: C:XYZProjectCollectionLincoln.vsXYZ.API18528tXYZ.APIbinXYZ.API.dll
    [10:22:07.363 Verbose] - Aggregator - assembly: C:XYZProjectCollectionLincoln.vsXYZ.API18528tXYZ.API.HelpersbinDebugXYZ.API.Global.dll
    [10:22:07.363 Verbose] - Aggregator - assembly: C:XYZProjectCollectionLincoln.vsXYZ.API18528tXYZ.API.MiscServicebinDebugXYZ.API.MiscService.dll
    [10:22:07.363 Verbose] - Aggregator - file: 'C:XYZProjectCollectionLincolnXYZ.API.MiscServiceRepositoriesValueRepository.cs - C:XYZProjectCollectionLincolnXYZ.API.MiscServiceXYZ.API.MiscService.csproj'
    [10:22:07.363 Verbose] - Aggregator - Skip reading spans for assembly C:XYZProjectCollectionLincoln.vsXYZ.API18528tXYZ.API.TestsbinDebugXYZ.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:XYZProjectCollectionLincoln.vsXYZ.API18528tXYZ.API.AccountClientServicebinDebugXYZ.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:XYZProjectCollectionLincoln.vsXYZ.API18528tXYZ.APIbinXYZ.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:XYZProjectCollectionLincoln.vsXYZ.API18528tXYZ.API.HelpersbinDebugXYZ.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:XYZProjectCollectionLincolnXYZ.API.MiscServiceXYZ.API.MiscService.csproj from the file span cache
    [10:22:07.363 Verbose] - Aggregator - Adding MVID 8e944276-0eec-43f4-aff3-07e40f8611dc for project C:XYZProjectCollectionLincolnXYZ.API.MiscServiceXYZ.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:XYZProjectCollectionLincoln.vsXYZ.API18528tXYZ.API.MiscServicebinDebugXYZ.API.MiscService.dll with MVID 8e944276-0eec-43f4-aff3-07e40f8611dc
    [10:22:07.363 Verbose] - Aggregator - Adding 3 methods from 'C:XYZProjectCollectionLincolnXYZ.API.MiscServiceRepositoriesValueRepository.cs - C:XYZProjectCollectionLincolnXYZ.API.MiscServiceXYZ.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.MiscServicebinDebugXYZ.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:XYZProjectCollectionLincolnXYZ.API.MiscServiceRepositoriesValueRepository.cs - C:XYZProjectCollectionLincolnXYZ.API.MiscServiceXYZ.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,并会将所有人都发布。 它没有得到正确的报告,环境被锁定。


    更新: 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标记导致实时单元测试失败。


    正如其他人所提到的,这个功能还有点bug。 我已经有了相当好的运气,但只要打开该功能并关注测试浏览器窗口 - 至少在我的盒子上,它运行测试,即使代码编辑器的装订线中有“减号” 。 不过,我已经看到该功能正常工作。

    我会继续使用该功能,并继续以任何方式向Microsoft反馈意见(应该有Visual Studio菜单栏中的“发送反馈”按钮)。

    更新:
    使用现有的项目,我根本没有在编辑器的装订线中看到UI ...我安装了15.3.4版。 我在Live Unit Tests中包含了一个完整的解决方案,并且重建...我在Output窗口中看到这条消息:

    [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软件包)时,我只有排除的测试/减号问题。


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

    还有一个问题,我刚刚遇到了这个问题。 这是非常类似的问题,就像你有。 你有多个单元测试项目吗? 如果是,那么你应该检查整个解决方案的Nuget包。 右键单击该解决方案,然后单击“Mange Nuget包for Solution ...”检查“Consolidate”选项卡,并确保在每个测试项目上安装相同的版本

  • MSTest.TestAdapter
  • MSTest.TestFramewor
  • 以下是错误设置的屏幕截图,这会导致整个Live单元测试功能失败。

    在这里输入图像描述

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

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

    链接地址: http://www.djcxy.com/p/73391.html

    上一篇: only minus's

    下一篇: Unit testing angular service with dependencies