在命令行上使用 dotnet test 获取测试结果

Get test results with dotnet test on command line

我使用以下 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)

如何显示测试结果?

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

顺便说一下,自从您发布问题后,csproj 的格式已大大简化。 xunit 测试项目如下所示(截至 Visual Studio 2017 RC,一月和 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>