【问题标题】:dotnet test will only run existing MSTest, and not include new xUnit testdotnet test 将只运行现有的 MSTest,而不包括新的 xUnit 测试
【发布时间】:2021-07-17 18:58:11
【问题描述】:

这是我的测试项目.csproj 的样子:

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

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>

    <IsPackable>false</IsPackable>

    <RootNamespace>MyProject.WebAPI.Test</RootNamespace>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
    <PackageReference Include="Mongo2Go" Version="2.2.14" />
    <PackageReference Include="MSTest.TestAdapter" Version="2.1.0" />
    <PackageReference Include="MSTest.TestFramework" Version="2.1.0" />
    <PackageReference Include="coverlet.collector" Version="1.2.0" />
    <PackageReference Include="Moq" Version="4.15.2" />
    <PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.1.10" />
    <PackageReference Include="Serilog.AspNetCore" Version="3.4.0" />
    <PackageReference Include="xunit" Version="2.4.1" />
    <PackageReference Include="xunit.runner.console" Version="2.4.1">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  </ItemGroup>

  <ItemGroup>
    <Folder Include="Domain\" />
    <Folder Include="Controllers\" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\MyProject.Data.csproj" />
    <ProjectReference Include="..\MyProject.WebAPI.csproj" />
  </ItemGroup>
  <ItemGroup>
    <None Remove="app_config.json" />
    <Content Include="app_config.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
  </ItemGroup>
</Project>

此项目中所有现有测试都是 MSTest,它们在类级别具有 [TestClass] 等属性,在单元测试方法级别具有 [TestMethod] 等属性。

我引入了一个 xUnit 测试类来测试控制器,并运行了 dotnet test,但它无法识别我的新 xUnit 测试类/其中包含 [Fact] 属性的 1 个测试方法。

如何让dotnet test 识别并运行 xUnit 和 MSTest 测试?我错过了一个包裹吗?

【问题讨论】:

    标签: .net-core mstest xunit


    【解决方案1】:
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    

    将此添加到我的MyProject.WebAPI.Test.csproj,然后运行dotnet test,它成功了!

    【讨论】:

      猜你喜欢
      • 2019-05-26
      • 1970-01-01
      • 2020-11-05
      • 1970-01-01
      • 1970-01-01
      • 2014-01-30
      • 1970-01-01
      • 2010-09-26
      • 1970-01-01
      相关资源
      最近更新 更多