代码之家  ›  专栏  ›  技术社区  ›  goku_da_master

在visual studio中运行单元测试时出错:缺少测试用例对象

  •  54
  • goku_da_master  · 技术社区  · 6 年前

    使用resharper从visual studio运行单元测试时,我遇到以下错误:

    Test-case objects missing for the following elements: ... Rebuild the project and try again

    在单元测试方法旁边的工具提示中,它表示: Inconclusive: Test not run 我想它说 Unit test skipped 在某一点上。Resharper显示灰色眼睛图标。

    visual studio的测试资源管理器也存在wierd问题。它不会显示我的所有单元测试。事实上,我遗漏了200多个单元测试。它们只是不显示在测试资源管理器窗口中。我确实有一些测试出现,并且运行得很好。

    我已经尝试过的事情:重新启动我的机器,清理,重建,将所有依赖的项目更改为使用相同的项目。net framework 4.7。

    我正在使用VS 2017。net Framework 4.7、Resharper和MSTest。都有最新的更新和版本。

    11 回复  |  直到 6 年前
        1
  •  46
  •   Bernard Vander Beken Harald Coppoolse    5 年前

    我在删除所有nuget包后遇到了此错误,因为我更改了。net版本,不需要任何编译。

    重新安装MSTest后。TestAdapter nuget package ReSharper按预期再次开始运行我的单元测试。

    Install-Package MSTest.TestAdapter

        2
  •  18
  •   gabrielkerekes    6 年前

    我知道这不能回答OP的问题,因为他/她已经尝试过了,但也许它会帮助其他人。

    对我来说,简单地重新启动Visual Studio解决了 以下元素缺少测试用例对象:。。。重建项目并重试 问题

        3
  •  5
  •   goku_da_master    6 年前

    撞了一天后,我让测试浏览器开始工作。这是目标平台。

    在正在构建的单元测试项目属性中,我将平台目标设置为x64。我将它切换到AnyCPU,测试浏览器立即找到了我丢失的单元测试。然而,resharper仍然给我同样的错误。如果我找到解决方案,我会更新。同时,我现在至少可以运行和调试我的单元测试了。

        4
  •  3
  •   Daniël Tulp    5 年前

    对我来说,这是因为我安装了 FLEE ,这将在我的应用程序中插入以下行。我的测试项目的配置文件:

    <dependentAssembly>
      <assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
    </dependentAssembly>
    

    由于我的机器上没有安装版本4.1.2.0(我有4.0.0.0),测试项目在某个地方失败,出现了这个非常令人困惑的“错误消息”

    一旦我安装了早期版本(1.05)的fleed包(使用4.0.0.0),我在我的应用程序的bindingRedirect中将版本号更改为4.0.0.0。配置,一切又恢复正常了

        5
  •  2
  •   ekenman    6 年前

    我升级了MSTest。测试适配器从1.1.18到1.3.2。它最终为我解决了这个问题。

        6
  •  1
  •   Richard Moore    6 年前

    我的问题是使用了错误的生成配置。

    我的解决方案有相当多的项目和相当多的不同构建配置,我无意中选择了错误的项目配置,该项目配置没有正确设置以包含我尝试使用的测试项目。

        7
  •  1
  •   pilsdumps    6 年前

    我在使用F#项目时遇到了这种情况。在我的情况下,是在测试方法名称中包含括号导致了问题;

    [<TestMethod>]
    member x.``E is updated where generic form or visit should include (this) UPDATED VISIT AND FORM``() =
            let origExpr = "visit:form:INTQ1AB"
            let checkedExpr = "VISIT2:FormFour:INTQ1AB"
            ...
    

    导致了非决定性的测试,而移除了“(此)”周围的括号,如下所示

    [<TestMethod>]
    member x.``E is updated where generic form or visit should include this UPDATED VISIT AND FORM``() =
            let origExpr = "visit:form:INTQ1AB"
            let checkedExpr = "VISIT2:FormFour:INTQ1AB"
            ...
    

    允许测试成功完成。

        8
  •  0
  •   drobison    5 年前

    当我让Resharper通过NuGet搜索Nunit缺少的引用时,我遇到了这个问题。而不是下载。NET core兼容版本的软件包,我需要的,它抓住了。NET framework版本。我卸载了NUnit软件包,并使用NuGet软件包管理器重新安装以解决此问题。

        9
  •  0
  •   Lee Oades    5 年前

    在将解决方案克隆到新机器上后,我遇到了这个错误。问题是我没有安装指定的dotnet框架-我只安装了2.1和3.0,它需要2.2。公平地说,测试输出中的错误确实报告了以下情况:

    Testhost process exited with error: It was not possible to find any compatible framework version
    The specified framework 'Microsoft.NETCore.App', version '2.2.0' was not found.
      - The following frameworks were found:
          2.1.13 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
          3.0.0 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    You can resolve the problem by installing the specified framework and/or SDK.
    The .NET Core frameworks can be found at:
      - https://aka.ms/dotnet-download
    . Please check the diagnostic logs for more information.
    

    请注意,安装丢失的框架后,Visual Studio需要重新启动。

        10
  •  0
  •   rpg II    5 年前

    当我更新一些测试项目以使用新的项目文件格式时,我遇到了这个问题,其中一些项目仍然需要包含应用程序。配置文件,当运行测试时,我得到了这些消息

    • 以下元素缺少测试用例对象。。。
    • 缺少测试用例。重建项目并重试

    正在删除应用程序运行时部分中的所有程序集绑定。config为我修复了它-即在runtime部分删除类似的条目

    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
    
        11
  •  0
  •   ekimpl    4 年前

    错误应该在visible Studio的输出窗口中可见。您可能需要在选项中更改为详细。

    在我的例子中,这是因为我引用的dll没有强名称。