gpt4 book ai didi

c# - 错误 : VS2017 Live Unit Testing - only minus's - doesn't work

转载 作者:IT王子 更新时间:2023-10-29 03:56:36 30 4
gpt4 key购买 nike

TL; 博士;编辑 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方法并选择创建单元测试:

  • enter image description here
  • 使用这些设置创建一个带有测试的新单元测试项目:

  • enter image description here
  • 添加单元测试

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

    Assert.IsTrue(3 == r);
    }
  • 测试菜单 > 实时单元测试 > 开始
  • AddTest() 上的上下文菜单> 实时测试 > 包括

  • 现在更改 Add 的 + 符号到 -

    Live Unit Testing 有效,更改 - 符号回 + 并且现场测试通过了!!

    现在添加对 Nuget DLL 的引用(任何人都会这样做) - Live Unit Testing 不再有效!或者干脆关闭解决方案,重新打开它,Live Unit Testing 就不再起作用了!



    我已经设置了一个 MSUnitTest v2 项目并开始了 Live Unit Testing。我正在使用 Web Api 2 .Net 项目(完整框架 v4.5.2)。

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

    我更改的代码与他们在 Live Unit Testing in Visual Studio 2017 video 中所做的相同时钟出现在减号上,但随后什么也没有......

    enter image description here

    当我调试它时,单元测试将通过:

    enter image description here

    当我将鼠标悬停在蓝色减号上时,消息是“由 0 个测试覆盖”

    我发现您需要 MSTest.TestAdapter MSTest.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 user got an issue with Live Unit Testing but its a Null Exception问题。我试过 solution in comments从 Gac 中删除 Microsoft.VisualStudio.QualityTools.UnitTestFramework,当我尝试从 C:\Windows\assembly 卸载时,我的访问被拒绝并通过开发人员命令提示符卸载:
    GacUtil /u Microsoft.VisualStudio.QualityTools.UnitTestFramework

    结果是:

    Assembly: Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL Unable to uninstall: assembly is required by one or more applications



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

    编辑 1:

    在 VS > 工具 > 选项 > 实时单元测试中,我将日志记录转为 Verbose。

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

    [15:48:26.521 Verbose] - TestDriver - TestDiscoverer log message: Warning - Configuration system failed to initialize



    遵循 this 中的一些答案我仍然无法摆脱“配置系统初始化失败”-不确定这是否是一个红鲱鱼,这是我迄今为止找到的唯一线索......

    编辑 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。我是按照 these instructions to overcome the Access Denied 做的:

    enter image description here

    这导致找到了潜在的根本原因之一。我开始看到 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.

    我给了自己所有这些目录的权限,只是为了排除任何权限问题:

    enter image description here

    这仍然不起作用,但是似乎我越来越接近了,因为实时单元测试需要更长的时间才能工作(即出现在减号顶部的时钟需要更长的时间来处理)。

    然后我再次尝试了 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/

    问:为什么我在实时测试集中包含或排除测试后没有任何 react ?

    答:这是我们无法在 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>

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

    关于c# - 错误 : VS2017 Live Unit Testing - only minus's - doesn't work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44427076/

    30 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com