TUnit icon indicating copy to clipboard operation
TUnit copied to clipboard

Adding TUnit.Core to a Project referenced by a Test Project, Test platform stops discovering the tests.

Open Arthus15 opened this issue 1 year ago • 10 comments

Description

I've created a TUnit test projects and I wanted to create a TestCommon project to share some features like CustomFormatters. If I add the TUnit package it tries to run it as a test, so I decided to add TUnit.Core as recommended in the documentation, however this is not possible as all test stops being discovered and thus they stop run on the build.

I'm using TUnit latest version.

Arthus15 avatar Nov 11 '25 12:11 Arthus15

Can you share how the csproj's look?

thomhurst avatar Nov 11 '25 13:11 thomhurst

Can you share how the csproj's look?

Sure!

<Project Sdk="Microsoft.NET.Sdk">
    <ItemGroup>
        <PackageReference Include="Bogus"/>
        <PackageReference Include="AwesomeAssertions"/>
         <PackageReference Include="TUnit.Core"/>
    </ItemGroup>
</Project>

Referenced project:

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

    <ItemGroup>
        <PackageReference Include="AwesomeAssertions"/>
        <PackageReference Include="Bogus"/>
        <PackageReference Include="Microsoft.Extensions.Hosting"/>
        <PackageReference Include="coverlet.collector">
            <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
            <PrivateAssets>all</PrivateAssets>
        </PackageReference>
        <PackageReference Include="Microsoft.Identity.Client"/>
        <PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage"/>
        <PackageReference Include="Microsoft.Testing.Extensions.TrxReport"/>
        <PackageReference Include="NSubstitute"/>
        <PackageReference Include="TUnit"/>
    </ItemGroup>


    <ItemGroup>
        <ProjectReference Include="..\MyProject.TestCommon\MyProject.TestCommon.csproj"/>
    </ItemGroup>

</Project>

Arthus15 avatar Nov 11 '25 14:11 Arthus15

Hmm that looks okay, apart from coverlet.collector - Which should be removed since it's replaced by Microsoft.Testing.Extensions.CodeCoverage.

Is this in an IDE you're not seeing tests? Or even using dotnet run or dotnet test doesn't work?

thomhurst avatar Nov 11 '25 18:11 thomhurst

Hmm that looks okay, apart from coverlet.collector - Which should be removed since it's replaced by Microsoft.Testing.Extensions.CodeCoverage.

Is this in an IDE you're not seeing tests? Or even using dotnet run or dotnet test doesn't work?

Yeh, I have the rtx and the coversge working already.

Im using rider, when I reference my library it suddenly stop working everywhere. I shaw the logs and it seems to be failing on the Test Platform, I will try to find the stacktrace and share it with you.

Arthus15 avatar Nov 11 '25 19:11 Arthus15

Image

Is the 2nd box checked for you? If so, try unchecking and then rebuild your solution

thomhurst avatar Nov 11 '25 19:11 thomhurst

Image

Is the 2nd box checked for you? If so, try unchecking and then rebuild your solution

I tried thar but still nothing, but also dotnet run/test does't run the test either

Arthus15 avatar Nov 11 '25 20:11 Arthus15

Ooh something is definitely broken then if the CLI won't run it.

Yeah if you can find that stacktrace that'd be helpful

thomhurst avatar Nov 11 '25 20:11 thomhurst

Also are your TUnit.Core and TUnit package versions in sync?

thomhurst avatar Nov 11 '25 22:11 thomhurst

Yeah if you can find that stacktrace that'd be helpful

████████╗██╗   ██╗███╗   ██╗██╗████████╗
╚══██╔══╝██║   ██║████╗  ██║██║╚══██╔══╝
   ██║   ██║   ██║██╔██╗ ██║██║   ██║
   ██║   ██║   ██║██║╚██╗██║██║   ██║
   ██║   ╚██████╔╝██║ ╚████║██║   ██║
   ╚═╝    ╚═════╝ ╚═╝  ╚═══╝╚═╝   ╚═╝

   TUnit v0.77.3.0 | 64-bit | Darwin 24.6.0 Darwin Kernel Version 24.6.0: Mon Jul 14 11:30:40 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6041 | osx-arm64 | .NET 9.0.10 | Microsoft Testing Platform v2.0.1

   Engine Mode: SourceGenerated

Unhandled exception. System.TypeLoadException: Method 'CreateTestVariant' in type 'TUnit.Engine.Services.TestRegistry' from assembly 'TUnit.Engine, Version=0.77.3.0, Culture=neutral, PublicKeyToken=b8d4030011dbd70c' does not have an implementation.
   at TUnit.Engine.Framework.TUnitServiceProvider..ctor(IExtension extension, ExecuteRequestContext context, ITestExecutionFilter filter, IMessageBus messageBus, IServiceProvider frameworkServiceProvider, ITestFrameworkCapabilities capabilities)
   at TUnit.Engine.Framework.TUnitTestFramework.<>c__DisplayClass20_0.<GetOrCreateServiceProvider>b__0(String _)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at TUnit.Engine.Framework.TUnitTestFramework.GetOrCreateServiceProvider(ExecuteRequestContext context)
   at TUnit.Engine.Framework.TUnitTestFramework.ExecuteRequestAsync(ExecuteRequestContext context)
   at Microsoft.Testing.Platform.Requests.TestHostTestFrameworkInvoker.ExecuteRequestAsync(ITestFramework testFramework, TestExecutionRequest request, IMessageBus messageBus, CancellationToken cancellationToken) in /_/src/Platform/Microsoft.Testing.Platform/Requests/TestHostTestFrameworkInvoker.cs:line 72
   at Microsoft.Testing.Platform.Requests.TestHostTestFrameworkInvoker.ExecuteAsync(ITestFramework testFramework, ClientInfo client, CancellationToken cancellationToken) in /_/src/Platform/Microsoft.Testing.Platform/Requests/TestHostTestFrameworkInvoker.cs:line 61
   at Microsoft.Testing.Platform.Hosts.CommonHost.ExecuteRequestAsync(ProxyOutputDevice outputDevice, ITestSessionContext testSessionInfo, ServiceProvider serviceProvider, BaseMessageBus baseMessageBus, ITestFramework testFramework, ClientInfo client) in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs:line 141
   at Microsoft.Testing.Platform.Hosts.ConsoleTestHost.InternalRunAsync(CancellationToken cancellationToken) in /_/src/Platform/Microsoft.Testing.Platform/Hosts/ConsoleTestHost.cs:line 82
   at Microsoft.Testing.Platform.Hosts.ConsoleTestHost.InternalRunAsync(CancellationToken cancellationToken) in /_/src/Platform/Microsoft.Testing.Platform/Hosts/ConsoleTestHost.cs:line 114
   at Microsoft.Testing.Platform.Hosts.CommonHost.RunTestAppAsync(CancellationToken testApplicationCancellationToken) in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs:line 115
   at Microsoft.Testing.Platform.Hosts.CommonHost.RunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs:line 38
   at Microsoft.Testing.Platform.Hosts.CommonHost.RunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs:line 74
   at Microsoft.Testing.Platform.Builder.TestApplication.RunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs:line 227
   at FiscalizationService.IntegrationTests.MicrosoftTestingPlatformEntryPoint.Main(String[] args) in /Users/user/Desktop/workspace/fiscalization-service/tests/MyApp.IntegrationTests/obj/Debug/net9.0/MicrosoftTestingPlatformEntryPoint.cs:line 18
   at MyApp.IntegrationTests.MicrosoftTestingPlatformEntryPoint.<Main>(String[] args)

Arthus15 avatar Nov 12 '25 13:11 Arthus15

Also are your TUnit.Core and TUnit package versions in sync?

This was the issue, somehow the version that it got installed was 1.0.78 😶‍🌫️. Now is working perfectly! sorry for the inconvenience!

Arthus15 avatar Nov 12 '25 13:11 Arthus15