TUnit icon indicating copy to clipboard operation
TUnit copied to clipboard

TUnit not discovering tests in Rider on Mac after v0.21.7

Open koddek opened this issue 7 months ago • 3 comments

On Rider on Mac, TUnit versions from v0.21.13 up to v0.22.24 (I tested all versions in this range) fail to display the play button in the IDE. If the button does appear (sometimes in version 0.21.13), it is crossed out and displays the error 'Not runnable: Exception occurred during exploration' upon hovering over it. Clicking the button shows the message 'Why can't I run tests?'. Subsequently, clicking this message opens the text file: FailedUnitTestExploration.txt:

Unfortunately, it's impossible to discover unit tests in some of your projects. :(
Below you can find the error details for each project.

Project: <PROJECTNAME>.Tests (/<PATH/TO/PROJECT>/<PROJECTNAME>/tests/<PROJECTNAME>.Tests/bin/Debug/net9.0/<PROJECTNAME>.Tests.dll)
  Exception occurred during exploration.
    JetBrains.Diagnostics.Assertion+AssertionException: Could not load parent for 'global::TUnit.Core.ArgumentsAttribute:0:TL-ARGS1:<PROJECTNAME>.Tests.AdvancedUsageTests.From_ThrowsArgumentException_WhenValueIsNonPositive(int):0' <4> (hc 26880221): no element with id <449>
       at JetBrains.Diagnostics.Assertion.Fail(String message)
       at JetBrains.ReSharper.UnitTestFramework.Persistence.LevelDb.LazyLoading.UnitTestElementParentInterceptor.InterceptGet(UnitTestElement entity, IUnitTestElement value)
       at JetBrains.ReSharper.UnitTestFramework.Persistence.LevelDb.Intercept.PropertyInterceptor`2.InterceptGet(Object target, String propertyName, Object value)
       at JetBrains.ReSharper.UnitTestFramework.Persistence.LevelDb.Intercept.AggregatingPropertyInterceptorFactory.AggregatingInterceptor.InterceptGet(Object target, String propertyName, Object value)
       at TestingPlatformElementLevelDbProxy.get_Parent()
       at JetBrains.ReSharper.UnitTesting.VsTest.Provider.TestingPlatform.Elements.TestingPlatformElement.GetDeclaredElement()
       at JetBrains.ReSharper.UnitTesting.VsTest.Provider.TestingPlatform.Elements.TestingPlatformElement.GetProjectFiles()
       at JetBrains.ReSharper.UnitTestFramework.Persistence.LevelDb.UnitTestElementPersister.CompareProjectFiles(IUnitTestElement discovered, IUnitTestElement existing)
       at JetBrains.ReSharper.UnitTestFramework.Persistence.LevelDb.UnitTestElementPersister.DetectChanges(IUnitTestElement transient, IUnitTestElement persisted)
       at JetBrains.ReSharper.UnitTestFramework.Persistence.LevelDb.UnitTestTransaction.PerformUpdate(IUnitTestElement element)
       at JetBrains.ReSharper.UnitTestFramework.Persistence.LevelDb.UnitTestTransaction.ProcessAll(WorkingSet set, Action`1 worker, Stopwatch stopwatch)
       at JetBrains.ReSharper.UnitTestFramework.Persistence.LevelDb.UnitTestTransaction.CommitCore()
       at JetBrains.ReSharper.UnitTestFramework.Persistence.LevelDb.UnitTestTransaction.Commit()
       at System.Threading.Tasks.Task`1.InnerInvoke()
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
    --- End of stack trace from previous location ---
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
    --- End of stack trace from previous location ---
       at JetBrains.ReSharper.UnitTestFramework.Exploration.UnitTestDiscoveryTransaction.CommitAsync(CancellationToken ct)
       at JetBrains.ReSharper.UnitTestFramework.Exploration.Artifacts.UnitTestArtifactExplorationRunner.ApplyExplorationResults(IExplorationResult[] results, IUnitTestDiscoveryTransaction tx, Boolean supportedByProvider, CancellationToken token)
       at JetBrains.ReSharper.UnitTestFramework.Exploration.Artifacts.UnitTestArtifactExplorationRunner.ProcessProject(IExplorationTarget target, CancellationToken token)

It works up till version 0.21.7. You have to close and reopen the IDE then rebuild the project to test each upgrade/downgrade of TUnit, so the IDE is properly refreshed.

koddek avatar May 28 '25 21:05 koddek

So they fail even after restarting?

thomhurst avatar May 28 '25 21:05 thomhurst

If that's the cases and a invalidate cache and restart + rebuild doesn't fix it either, then I'd raise it with Jetbrains (assuming you can run from the CLI fine)

thomhurst avatar May 28 '25 22:05 thomhurst

Running the test project as a console application (what I believe is referred to as CLI) works.

I tried invalidating the cache, restarting, and rebuilding, all to no avail. Within the project structure, right-clicking to 'Run Unit Tests' sometimes works, while other times nothing happens. The same applies to right-clicking on individual test class files. For some files, the 'Run Unit Tests' option is grayed out. These results occur randomly, so I cannot definitively say what actions lead to it working one way or the other.

koddek avatar May 28 '25 22:05 koddek

@koddek running into this as well.

Did you reach out to JetBrains yet?

brendonparker avatar Jun 02 '25 15:06 brendonparker

@brendonparker No I have not reached out yet. Since I seemed like the only one I was not sure if the problem was on my end. You could go ahead and reach out and share the link. I will vote on it. Or wait until I get around to it in a few days.

koddek avatar Jun 03 '25 10:06 koddek

I opened this issue: RIDER-126435 Gutter Icons not showing for Tests with TUnit 0.21.7 or later

brendonparker avatar Jun 03 '25 13:06 brendonparker

Just to clarify, this problem is not Mac-exclusive, unfortunately I encountered the problem myself yesterday under Windows. With 0.21.7 it always seems to work for me, from 0.21.13 it no longer works. Therefore, in my opinion, the issue at Jetbrains is not quite correct @brendonparker.

@thomhurst I took a look at the changes between 0.21.7 and 0.21.13. How relevant was the TestArtifact? In my opinion, this is the only serious change (apart from a few package references).

akanwischer avatar Jun 11 '25 09:06 akanwischer

I think the package references are the problem. For the new test artifact, I had to update the testing platform packages. And I'm willing to bet that's the problem. And I'd still say it's a Jetbrains problem. It doesn't like something to do with the new testing platform packages?

thomhurst avatar Jun 11 '25 10:06 thomhurst

For what it’s worth, I gave up fighting it and switched to xunit. Way less friction.

brendonparker avatar Jun 11 '25 10:06 brendonparker

With 0.21.7 it always seems to work for me, from 0.21.13 it no longer works.

Same for me. I was not clear in what I wrote. What I should have said was, the last working version is 0.21.7. The versions after it onward are broken. So I just stay on version 0.21.7.

koddek avatar Jun 12 '25 14:06 koddek

The version after 0.21.7 is 0.21.13 and Microsoft.Testing.Platform is updated from 1.6.3 to 1.7.0.

I can guarantee this is the problem. Rider doesn't like the new version for some people. So it isn't a TUnit bug, it's a Rider/MTP bug.

But annoyingly because TUnit sits on top of MTP it's affecting it 👎

thomhurst avatar Jun 12 '25 14:06 thomhurst

I've just added that information onto the issue on youtrack

thomhurst avatar Jun 12 '25 14:06 thomhurst

It seems to work again after upgrading to Rider 2025.2 EAP4

w1am avatar Jun 13 '25 13:06 w1am

Fixed in Rider 2025.1.4 RIDER-126435

iwedaz avatar Jul 06 '25 20:07 iwedaz

I can confirm that the issue is fixed on Rider 2025.1.4. Tested and working with the latest TUnit v0.25.21. This issue can be closed. Thanks.

koddek avatar Jul 07 '25 22:07 koddek