dotnet 测试将仅 运行 个现有的 MSTest,并且不包括新的 xUnit 测试
dotnet test will only run existing MSTest, and not include new xUnit test
这是我的测试项目 .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,它们在 class 级别具有 [TestClass]
等属性,在单元测试方法级别具有 [TestMethod]
等属性。
我引入了一个 xUnit 测试 class 来测试控制器,运行 dotnet test
,但它不识别我的新 xUnit 测试 class / 1 测试方法在其中,具有 [Fact]
属性。
如何让 dotnet test
识别并 运行 xUnit 和 MSTest 测试?我是不是少了一个包裹?
<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
,成功了!
这是我的测试项目 .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,它们在 class 级别具有 [TestClass]
等属性,在单元测试方法级别具有 [TestMethod]
等属性。
我引入了一个 xUnit 测试 class 来测试控制器,运行 dotnet test
,但它不识别我的新 xUnit 测试 class / 1 测试方法在其中,具有 [Fact]
属性。
如何让 dotnet test
识别并 运行 xUnit 和 MSTest 测试?我是不是少了一个包裹?
<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
,成功了!