Adding TUnit.Core to a Project referenced by a Test Project, Test platform stops discovering the tests.
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.
Can you share how the csproj's look?
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>
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?
Hmm that looks okay, apart from
coverlet.collector- Which should be removed since it's replaced byMicrosoft.Testing.Extensions.CodeCoverage.Is this in an IDE you're not seeing tests? Or even using
dotnet runordotnet testdoesn'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.
Is the 2nd box checked for you? If so, try unchecking and then rebuild your solution
![]()
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
Ooh something is definitely broken then if the CLI won't run it.
Yeah if you can find that stacktrace that'd be helpful
Also are your TUnit.Core and TUnit package versions in sync?
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)
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!