【问题标题】:.NET Standard 1.5 XUnit console runner - How to run my unit tests?.NET Standard 1.5 XUnit 控制台运行器 - 如何运行我的单元测试?
【发布时间】:2017-03-20 23:15:01
【问题描述】:

我有一个使用 .NET Standard 1.5 配置的测试项目

IDE:Visual Studio 2017 社区

我已包含xunitxunit.runner.console,但我无法运行测试。 我在测试项目上尝试了dotnet test,但出现以下错误

找不到源 'D:\Dev\Visual Studio 的 testhost.dll 2017\CSharpSeven.NewFeatures\CSharpSeven.NewFeatures\CSharpSeven.Tests\bin\Debug\netstandard1.5\CSharpSeven.Tests.dll'。 确保测试项目具有包的 nuget 引用 “microsoft.testplatform.testhost”。

我的.csproj 如下:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard1.5</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.TestPlatform.TestHost" Version="15.0.0" />
    <PackageReference Include="System.ValueTuple" Version="4.3.0" />
    <PackageReference Include="xunit" Version="2.2.0" />
    <PackageReference Include="xunit.runner.console" Version="2.2.0" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\CSharpSeven\CSharpSeven.csproj" />
  </ItemGroup>

</Project>

我一直在努力让测试运行,有人可以帮忙吗?

【问题讨论】:

    标签: visual-studio-2017 xunit .net-standard .net-standard-1.5


    【解决方案1】:

    测试项目需要是可运行的应用程序。您需要针对特定​​的运行时。例如:

      <PropertyGroup>
        <TargetFramework>netcoreapp1.1</TargetFramework>
      </PropertyGroup>
    

    查看此答案了解更多信息

    Can't get XUnit tests to run with .NET Core

    【讨论】:

      【解决方案2】:

      您是否尝试过先进行还原和构建?

      dotnet restore
      dotnet build
      

      这应该添加任何缺少的包,然后您可以运行测试。

      【讨论】:

        猜你喜欢
        • 2017-07-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-11-16
        • 2016-11-18
        • 2017-10-30
        相关资源
        最近更新 更多