Where are my xUnit tests?

Lately, I am doing more .NET related work on MacOS. Visual Studio Code + .NET Core 2.0 are proving to be an awesome development experience.

Cross-platform .NET development does have its challenges. Take this error for instance:

No test is available in "my cool project". Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.

What... is this?

My tests annotated with Fact attributes.

[Fact]
public async Task ShouldContainHeaderKey()
{
    //...stuff happens.
}

My project file has the appropriate package references (I think...).

<ItemGroup>
  <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
  <PackageReference Include="xunit" Version="2.3.1" />
</ItemGroup>

<ItemGroup>
  <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
  <DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>

Even using xunit command directly from Terminal works as expected.

$ dotnet xunit

However, this does not work.

$ dotnet test

...
...
...

Apparently, I did not include the xunit.runner.visualstudio package. This appears to be a requirement, even on MacOS.

¯\(ツ)

$ dotnet add package xunit.runner.visualstudio

This fixes the issue; however, I wish I get the last four hours back.

Enjoy!

Show Comments