Here's what my Test project .csproj
looks like:
<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>
All existing tests in this project are MSTest, they have attributes like [TestClass]
at the class level and [TestMethod]
at the unit test method level.
I introduced an xUnit test class to test a controller, and ran dotnet test
, but it does not recognize my new xUnit test class / 1 test method in it, with [Fact]
attribute.
How can I make dotnet test
recognize and run both xUnit and MSTest tests? Am I missing a package?
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Added this to my MyProject.WebAPI.Test.csproj
and then ran dotnet test
, it worked!