TUnit Test is not showing in the Test Explorer

Muhammad Ghozlan 0 Reputation points
2024-09-25T00:53:37.0866667+00:00

I created this simple test:

namespace TestingApplication

{

    public class TestsExample

    {

        [Test]

        public async Task TestExample()

        {

            var sum=Add(3,5);

            await Assert.That(sum).IsEqualTo(3);

        }

        private int Add(int x, int y)

        {

            return x + y;

        }

    }

}

and these are my application packages: <Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>

    <OutputType>Exe</OutputType>

    <TargetFramework>net8.0</TargetFramework>

    <ImplicitUsings>enable</ImplicitUsings>

    <Nullable>enable</Nullable>

  </PropertyGroup>

  <ItemGroup>

    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />

    <PackageReference Include="TUnit" Version="0.1.818" />

    <PackageReference Include="xunit" Version="2.9.1" />

    <PackageReference Include="xunit.runner.visualstudio" Version="3.0.0-pre.35">

      <PrivateAssets>all</PrivateAssets>

      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

    </PackageReference>

  </ItemGroup>

</Project>

of course I checked "Use testing platform server mode" from the Preview Features in my Microsoft Visual Studio 2022, but I still cannot see the test on my Test Explorer.

However, when I run the command "dotnet test" in the Terminal it comes back with a success: "Tests succeeded"

Visual Studio Testing
Visual Studio Testing
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Testing: The act or process of applying tests as a means of analysis or diagnosis.
351 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anna Xiu-MSFT 30,011 Reputation points Microsoft Vendor
    2024-09-25T07:29:04.9+00:00

    Hi @Muhammad Ghozla, 

    Welcome to Microsoft Q&A! 

    Please edit your project file (.csproj) as the following:

    <Project Sdk="Microsoft.NET.Sdk">
    	<PropertyGroup>
    		<OutputType>Exe</OutputType>
    		<TargetFramework>net8.0</TargetFramework>
    		<ImplicitUsings>enable</ImplicitUsings>
    		<Nullable>enable</Nullable>
    	</PropertyGroup>
      <ItemGroup>
    	  <PackageReference Include="TUnit" Version="0.1.818" />
      </ItemGroup>
    </Project>
    

    The package Microsoft.NET.Test.Sdk is not compatible with TUnit. And if you use the xUnit framework to run TUnit tests, you need to manually delete xUint package reference.

    Sincerely,

    Anna


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".  Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.