JetBrains Rider unable to detect UnitTests
Asked Answered
H

8

16

I am using JetBrains Rider to run unit tests for a .net Core project. And for some reason, it is failing to recognize any of the test cases in the solution.

These test cases were being detected before and now suddenly they are not. I restarted the Rider and rebuilt the solution and it seems that the problem does not go away.

Any suggestions on how to debug this?

Hummock answered 20/4, 2021 at 20:57 Comment(2)
Try looking in the backend.log for some obvious reason. Otherwise, submit a ticket to Rider team with Help->Report a Bug, agree to attach logs.Kandrakandy
Not sure if this is a solution, but when clicked Build selected projects on unit test project, Run unit tests button wasn't disabled anymoreLaureate
C
17

I had a similar problem with Rider 2023.1.3. Run/Debug Unit Test options were disabled for some test classes, besides these classes were not displayed in the Unit Tests Explorer and they are disappeared from test session.

File -> Invalidate Caches... and restarting of Rider resolved the problem.

Catamnesis answered 31/7, 2023 at 10:31 Comment(4)
Ridiculous that this was the answer, but just to confirm, this worked for me as well.Stoush
This fixed my issue. I setup the Visual studio IDE location too.Mariejeanne
Worked for me as well (Rider 2023.3.2).Moue
so frustrating, thanks for the help :)Lieabed
C
3

I had exactly this problem with Rider a while ago. My teammates could still run our NUnit tests (both in Rider and Visual Studio) but I couldn't. The Run Unit Tests menu items were all disabled and the run icons that usually appear in the left margin alongside the test fixture class and test methods didn't appear.

It turned out to be a bug in Rider causing an incompatibility between versions of .NET Core and the Microsoft.NET.Test.Sdk library. I'd run the Visual Studio Updater and my teammates hadn't, so I was on the latest version of .NET Core and they weren't.

Here's the bug I filed with JetBrains. As you can see, they migrated it to ReSharper but the bug affected Rider too. Although it was fixed at the time I think I've seen it again since.

To find out if you've got the same problem, try the following:

  • Make sure .NET (Core) and the Microsoft.NET.Test.Sdk library are both up-to-date.
  • If this doesn't work, downgrade Microsoft.NET.Test.Sdk to an older version (anything before 16.3.0 worked for me).
Centi answered 30/4, 2021 at 20:5 Comment(0)
A
3

I had a similar problem where Rider (2023.1.3) disabled the Run Unit Tests option when right-clicking on a Test project in the Solution Explorer.

The fix for me was to go into the Test project and right-click on an individual test file and I could run that test.

Then the project was magically testable again.

Amarette answered 19/7, 2023 at 21:41 Comment(0)
S
0

We had that problem and we use MSTest. We tried rebuilding, cleaning, etc. and none of that worked. But the following did work.

  • Comment out '[TestClass]'
  • Rebuild

All the menus were back to functioning as expected. I hope that helps future me when I come back into this question in a couple of months.

Shrike answered 6/12, 2022 at 20:16 Comment(0)
A
0

In my case, there were Git conflicts in the .csproj file that I had not noticed. When I resolved the conflicts, Rider once again recognized the test file as before.

I had looked at the project view to see what files had errors, but none showed. Evidently, the merge conflicts were causing that issue, too.

Aeromancy answered 8/8, 2023 at 19:48 Comment(0)
P
0

I had a similar issue: Visual Studio would recognize and run unit test projects, but Rider wouldn't recognize them (Unit Test Explorer) nor let me manually run them (Right-Click->Run Unit Test).

The unit tests are targeting older framework versions (4.6.1 and some .net standard 2.0) for a legacy product.

The fix for me was to ensure the MSTest.TestAdapter package was installed. The MSTest.TestFramework was installed and its version matched all other working projects. But the newly-created projects did not have this package (MSTest.Adapter) included automatically / when creating the project using the latest version of Visual Studio at the time (August 2023).

TL;DR: ensure that both MSTest.TestFramework AND MSTest.TestAdapter are added as nuget packages. You may also have to manually update the csproj to ensure the correct and tags exist. Of note for my situation: the test adapter locations were relative paths that look for the packages directory of the solution. e.g.

  <Import Project="..\..\..\..\packages\MSTest.TestAdapter.2.2.3\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\..\..\..\packages\MSTest.TestAdapter.2.2.3\build\net45\MSTest.TestAdapter.props')" />
  <Import Project="..\..\..\..\packages\MSTest.TestAdapter.2.2.3\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\..\..\..\packages\MSTest.TestAdapter.2.2.3\build\net45\MSTest.TestAdapter.targets')" />

And then in the "EnsureNuGetPackageBuildImports" target that some projects have, the similar path structure should be present in the error entries:

<Error Condition="!Exists('..\..\..\..\packages\MSTest.TestAdapter.2.2.3\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\MSTest.TestAdapter.2.2.3\build\net45\MSTest.TestAdapter.props'))" />
<Error Condition="!Exists('..\..\..\..\packages\MSTest.TestAdapter.2.2.3\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\MSTest.TestAdapter.2.2.3\build\net45\MSTest.TestAdapter.targets'))" />
Prepay answered 14/9, 2023 at 15:8 Comment(0)
P
0

tl;dr I had the wrong method signature on one method marked with MSTest attributes in my test class


I ran into this and it turned out that I had just added an MSTest attribute on a method with the wrong signature. In my case, I had to add TestContext to my class init method

From:

[ClassInitialize]
public static void Init(){ /* ... */ }

To:

[ClassInitialize]
public static void Init(TestContext context){ /* ... */ }

The Docs list *Attribute methods to make sure you have the correct signatures for.

Potash answered 10/1, 2024 at 19:27 Comment(0)
B
0

In my case it was my inattention. I've updated NUnit from 3.14.0 to 4.1.0 and my IDE version does not support running test with this version...

https://docs.nunit.org/articles/nunit/getting-started/upgrading.html

Birdseed answered 9/6, 2024 at 22:2 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.