C
C#2y ago
LukeJ

✅ Unit tests not appearing

Hello! For once I'm doing a little project in the console rather than in Unity, meaning for unit tests I'm having to add the package myself. I've added the NuGet packages NUnit and NUnit.Console, and I've written a test file that doesn't give any complains. When I try add run it though, the Unit Test tab of Rider show's no tests. I can't figure out why though. All I can think of is the assembly not being referenced, but Rider says it does that automatically for NUnit packages. Any ideas? I'm sure it's something simple didn't know was a step. Here's the test class, in case I've done something wrong there.
using NUnit.Framework;

[TestFixture]
public class UnitTests
{
[Test]
public void Test1()
{
Assert.That(4, Is.EqualTo(2 + 2));
}
}
using NUnit.Framework;

[TestFixture]
public class UnitTests
{
[Test]
public void Test1()
{
Assert.That(4, Is.EqualTo(2 + 2));
}
}
7 Replies
mtreit
mtreit2y ago
If you go to that folder on the command line (in PowerShell for instance) and run dotnet test does it work?
LukeJ
LukeJ2y ago
All it gave me was
Determining project to restore...
All projects are up-to-date for restore.
Determining project to restore...
All projects are up-to-date for restore.
mtreit
mtreit2y ago
mtreit
mtreit2y ago
Try that
dotnet new nunit --name TestProject
dotnet new nunit --name TestProject
If it works, compare the generated csproj with the one you have that isn't working.
LukeJ
LukeJ2y ago
Just making sure, since I saw two separate tutorials showing doing this with the project initially made as a unit testing project, it's not a problem adding in the packages afterwards, no? I'm adding these tests in part way through now I can see this project is big enough to need them. That works, yes. Got it. I needed Microsoft.NET.Test.Sdk. Thank you. Really doubt I'd have figured that out any time soon.
mtreit
mtreit2y ago
I think using one of the templates via dotnet new or using Visual Studio is always a good idea when you are bootstrapping a new project.
LukeJ
LukeJ2y ago
Sounds sensible. Really hadn't planned for this project to become so complicated though 😅 Guess that's how it always goes.