【问题标题】:Get test results with dotnet test on command line在命令行上使用 dotnet test 获取测试结果
【发布时间】:2017-04-11 10:00:03
【问题描述】:

我使用以下 csproj 文件创建了一个 ASP.NET Core 1.1 xunit 测试项目:

<Project ToolsVersion="15.0">

  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp1.6</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="**\*.cs" />
    <EmbeddedResource Include="**\*.resx" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Sdk" Version="1.0.0-alpha-20161104-2">
      <PrivateAssets>All</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0- preview-20161123-03" />
    <PackageReference Include="Microsoft.NETCore.App" Version="1.1.0" />
    <PackageReference Include="xunit" Version="2.2.0-beta4-build3444" />
  </ItemGroup>

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

  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

</Project>

我可以通过命令行使用dotnet test 运行该项目,但我看不到任何有关多少测试通过或失败的信息。

我使用的 Dotnet 命令行版本是:

.NET Command Line Tools (1.0.0-preview4-004124)

如何显示测试结果?

【问题讨论】:

    标签: asp.net-core xunit xunit.net


    【解决方案1】:

    要使 dotnet-test 正常工作,您还需要将 PackageReference 包含到 xunit.runner.visualstudio。

    顺便说一句,自从您发布问题以来,csproj 的格式已大大简化。 xunit 测试项目如下所示(截至 Visual Studio 2017 RC,1 月和 dotnet CLI 1.0.0-rc3-004350)。

    <Project Sdk="Microsoft.NET.Sdk">
    
    <PropertyGroup>
        <TargetFramework>netcoreapp1.0</TargetFramework>
    </PropertyGroup>
    
    <ItemGroup>
        <PackageReference Include="Microsoft.NET.Test.Sdk" Version="5.0.0-preview-20170125-04" />
        <PackageReference Include="xunit" Version="2.2.0-beta5-build3474" />
        <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0-beta5-build1225" />
    </ItemGroup>
    
    <ItemGroup>
        <ProjectReference Include="..\ClassLib\ClassLib.csproj"/>
    </ItemGroup>
    
    </Project>
    

    【讨论】:

    • Os 这在使用带有 Asp.Net Core 1.1 的 Visual Studio Code 时也有效吗?还是仅适用于 Visual Studio 2017?
    • 只需将 TargetFramework 值更改为 netcoreapp1.1
    猜你喜欢
    • 2018-09-29
    • 2020-11-05
    • 1970-01-01
    • 1970-01-01
    • 2018-08-29
    • 1970-01-01
    • 2022-11-21
    • 1970-01-01
    • 2016-10-11
    相关资源
    最近更新 更多