C
C#3mo ago
forge44

✅ Unit Testing in Rider not working

Hello, I've unsuccessfully attempted to use NUnit 3.14 with Net 8.0, and Xunit 2.5.3 with Net 8.0, and Xunit (2.0 or 2.1.0.3179) with Net 4.0, and NUnit 3.5 with Net 4.0 - all respectively shown in this video: https://www.youtube.com/watch?v=PyY5X7ylGOc I've also tried both with Net 7.0 According to NUnit, Net 4.0 should be compatible with any NUnit underneath 4.3; I'm surprised NUnit 3.5 didn't work with Net 4.0: https://docs.nunit.org/articles/vs-test-adapter/Supported-Frameworks.html Net 8.0 requires NUnit of at least 4.3.2; but Rider doesn't seem to have an option to use that version of NUnit, or to customize Xunit version; is it as simple as editing the version in the .csproj file?
37 Replies
forge44
forge44OP3mo ago
An error that shows up when I try to build a project with NUnit 3.5 and Net 4.0: Error CS0246 : The type or namespace name 'NUnit' could not be found (are you missing a using directive or an assembly reference?) referring to the line using NUnit.Framework; I tried manually adding NUnit through cmd with dotnet add package NUnit --version 3.5.0.0, but got Rider didn't like that: error: Error while adding package 'NUnit' to project 'E:\RiderProjects\FutileTest2\Test4\Test4.csproj'. The project does not support adding package references through the add package command.
Pobiega
Pobiega3mo ago
Weird, I use Rider and have had no problems with either NUnit or XUnit. Can you perhaps reproduce and upload to github or similar?
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
forge44
forge44OP3mo ago
Thanks for the responses. I took the 3.5.0.0 from the default generated .csproj file when Net 4.0 was selected, not sure what it means- it's at 3:00 in the video I posted. Now using Net 8- dotnet add package NUnit for me within the project folder returns:
Determining projects to restore...
Writing C:\Users\woodrow73\AppData\Local\Temp\tmpn2ngpn.tmp
info : X.509 certificate chain validation will use the default trust store selected by .NET for code signing.
info : X.509 certificate chain validation will use the default trust store selected by .NET for timestamping.
info : Adding PackageReference for package 'NUnit' into project 'E:\RiderProjects\PlzUnitTest_ManualAddPackage\TestNUnit\TestNUnit.csproj'.
error: There are no versions available for the package 'NUnit'.
Determining projects to restore...
Writing C:\Users\woodrow73\AppData\Local\Temp\tmpn2ngpn.tmp
info : X.509 certificate chain validation will use the default trust store selected by .NET for code signing.
info : X.509 certificate chain validation will use the default trust store selected by .NET for timestamping.
info : Adding PackageReference for package 'NUnit' into project 'E:\RiderProjects\PlzUnitTest_ManualAddPackage\TestNUnit\TestNUnit.csproj'.
error: There are no versions available for the package 'NUnit'.
dotnet new nunit -n new_project when used from my solution folder with a non-existing project name returns:
PS E:\RiderProjects\PlzUnitTest_ManualAddPackage> dotnet new nunit -n TestNUnit2
The template "NUnit 3 Test Project" was created successfully.

Processing post-creation actions...
Restoring E:\RiderProjects\PlzUnitTest_ManualAddPackage\TestNUnit2\TestNUnit2.csproj:
Determining projects to restore...
E:\RiderProjects\PlzUnitTest_ManualAddPackage\TestNUnit2\TestNUnit2.csproj : error NU1100: Unable to resolve 'coverlet.collector (>= 6.0.0)' for 'net8.0'.
E:\RiderProjects\PlzUnitTest_ManualAddPackage\TestNUnit2\TestNUnit2.csproj : error NU1100: Unable to resolve 'Microsoft.NET.Test.Sdk (>= 17.8.0)' for 'net8.0'.
E:\RiderProjects\PlzUnitTest_ManualAddPackage\TestNUnit2\TestNUnit2.csproj : error NU1100: Unable to resolve 'NUnit (>= 3.14.0)' for 'net8.0'.
E:\RiderProjects\PlzUnitTest_ManualAddPackage\TestNUnit2\TestNUnit2.csproj : error NU1100: Unable to resolve 'NUnit.Analyzers (>= 3.9.0)' for 'net8.0'.
E:\RiderProjects\PlzUnitTest_ManualAddPackage\TestNUnit2\TestNUnit2.csproj : error NU1100: Unable to resolve 'NUnit3TestAdapter (>= 4.5.0)' for 'net8.0'.
Failed to restore E:\RiderProjects\PlzUnitTest_ManualAddPackage\TestNUnit2\TestNUnit2.csproj (in 87 ms).
Restore failed.
Post action failed.
Manual instructions: Run 'dotnet restore'
PS E:\RiderProjects\PlzUnitTest_ManualAddPackage> dotnet new nunit -n TestNUnit2
The template "NUnit 3 Test Project" was created successfully.

Processing post-creation actions...
Restoring E:\RiderProjects\PlzUnitTest_ManualAddPackage\TestNUnit2\TestNUnit2.csproj:
Determining projects to restore...
E:\RiderProjects\PlzUnitTest_ManualAddPackage\TestNUnit2\TestNUnit2.csproj : error NU1100: Unable to resolve 'coverlet.collector (>= 6.0.0)' for 'net8.0'.
E:\RiderProjects\PlzUnitTest_ManualAddPackage\TestNUnit2\TestNUnit2.csproj : error NU1100: Unable to resolve 'Microsoft.NET.Test.Sdk (>= 17.8.0)' for 'net8.0'.
E:\RiderProjects\PlzUnitTest_ManualAddPackage\TestNUnit2\TestNUnit2.csproj : error NU1100: Unable to resolve 'NUnit (>= 3.14.0)' for 'net8.0'.
E:\RiderProjects\PlzUnitTest_ManualAddPackage\TestNUnit2\TestNUnit2.csproj : error NU1100: Unable to resolve 'NUnit.Analyzers (>= 3.9.0)' for 'net8.0'.
E:\RiderProjects\PlzUnitTest_ManualAddPackage\TestNUnit2\TestNUnit2.csproj : error NU1100: Unable to resolve 'NUnit3TestAdapter (>= 4.5.0)' for 'net8.0'.
Failed to restore E:\RiderProjects\PlzUnitTest_ManualAddPackage\TestNUnit2\TestNUnit2.csproj (in 87 ms).
Restore failed.
Post action failed.
Manual instructions: Run 'dotnet restore'
forge44
forge44OP3mo ago
Sure, I reproduced using Net 8, and 3 projects, a default console project, an NUnit default project, and an XUnit default project - https://github.com/wood73/PlzUnitTest Thanks for taking a look.
GitHub
GitHub - wood73/PlzUnitTest: An attempt at using NUnit and XUnit wi...
An attempt at using NUnit and XUnit with Net 8 using the IDE Rider - wood73/PlzUnitTest
forge44
forge44OP3mo ago
I also tried a 2023 version of Rider to no avail (I used the latest version for the tests above)
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
forge44
forge44OP3mo ago
I'll try anything :b I created that file in my solution folder and rebuilding + reloading my projects, I didn't observe changes.
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
Pobiega
Pobiega3mo ago
hm, the versions used in your xunit project are... weird
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
is what I would expect but yeah something seems to be wrong with your nuget, based on those errors
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
forge44
forge44OP3mo ago
I got it working! Thank you both- I had to remove Nuget from my system/user path variables
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
forge44
forge44OP3mo ago
I think I downloaded Nuget before the issue happened, and manually added it into my windows path/environment variable, so I'm guessing that Rider was mistakenly using the wrong version of Nuget somehow or caused some issue I don't understand. I'm re-adding it to my path/environment system variable to recreate the issue, and restarting Rider- weird, it still works, maybe that wasn't the issue. Here's what I did before it was solved: 1. remove nuget from both path variables 2. (probably incorrect step): remove dotnet from both path variables 3. use command: dotnet add package NUnit from CMD, inside an NUnit project (the CMD might've been opened before removing dotnet from path, hence why the dotnet command worked) Then it was solved even inside newly created Solutions. I've been re-installing Rider a few times, maybe if I re-install Rider when Nuget is set in my environment variables it'll recreate the issue. I don't know.
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
forge44
forge44OP3mo ago
yes
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
forge44
forge44OP3mo ago
ah
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
forge44
forge44OP3mo ago
no I just removed then re-added dotnet, it's possible that the dotnet it was pointing to was different before and after changing it, but I doubt it
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
forge44
forge44OP3mo ago
I'm on windows. Idk if it was different before but now it's pointing here
No description
forge44
forge44OP3mo ago
sure dotnet --info returns:
C:\Users\woodrow73>dotnet --info
.NET SDK:
Version: 8.0.402
Commit: 70aa751718
Workload version: 8.0.400-manifests.b6724b7a
MSBuild version: 17.11.4+37eb419ad

Runtime Environment:
OS Name: Windows
OS Version: 10.0.19045
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\8.0.402\

.NET workloads installed:
Configured to use loose manifests when installing new manifests.
There are no installed workloads to display.

Host:
Version: 8.0.8
Architecture: x64
Commit: 08338fcaa5

.NET SDKs installed:
7.0.410 [C:\Program Files\dotnet\sdk]
8.0.402 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
None

Environment variables:
Not set

global.json file:
Not found

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download
C:\Users\woodrow73>dotnet --info
.NET SDK:
Version: 8.0.402
Commit: 70aa751718
Workload version: 8.0.400-manifests.b6724b7a
MSBuild version: 17.11.4+37eb419ad

Runtime Environment:
OS Name: Windows
OS Version: 10.0.19045
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\8.0.402\

.NET workloads installed:
Configured to use loose manifests when installing new manifests.
There are no installed workloads to display.

Host:
Version: 8.0.8
Architecture: x64
Commit: 08338fcaa5

.NET SDKs installed:
7.0.410 [C:\Program Files\dotnet\sdk]
8.0.402 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
None

Environment variables:
Not set

global.json file:
Not found

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
forge44
forge44OP3mo ago
ok haha
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
forge44
forge44OP3mo ago
I'll try looking for a separate install location
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
forge44
forge44OP3mo ago
It might've been pointing to visual studio's dotnet - I actually deleted Visual studio 2017 and Visual studio 2019 at some point. Found 'em, deleted 7.0
No description
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
forge44
forge44OP3mo ago
got this for 4.5 so I kept it installed
No description
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
forge44
forge44OP3mo ago
whoops
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
forge44
forge44OP3mo ago
I don't think so, but I've programmed in C for cuda, and Java before, so I'm not sure if something else was wrong
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
forge44
forge44OP3mo ago
yea
Want results from more Discord servers?
Add your server