Search code examples
c#.net-corenunitasp.net-core-3.1visual-studio-2022

How to debug NUnit tests in Visual Studio 2022


I'm very new to Unit Testing and trying to implement NUnit in a C# Dotnet Core 3.1 project. I think the test is working, but I'd really like to debug (and single-step through) the test to make sure everything is working.

However, when I right-click on a test and select "debug", two things happen (or not):

  1. I get an error saying that "There were build errors. Would you like to continue and run tests from the last successful build?" (and when I look in the output window, there are no errors but two warnings saying that "ProjectData: Could not find project with GUID adf53ed2...".
  2. Debugging doesn't happen (no breakpoints are hit) but the test "runs" and passes.

I found a thread on Stackoverflow that said you had to set up an external program in the debug settings, but VS2022 does not have those screens or settings.

UPDATE: I created a stupid-simple dotnet core console project (and added NUnit in the same way) and debugging works just fine. So, it's something about the project I'm trying to add test to: it is a dotnet core 3.1 web project.

2nd UPDATE: so I created a stupid-simple dotnet core web project (and added NUnit) and debugging works just fine. So, it's something about my project (and probably related to that error message saying it can't find project guid: xxxxxxx (don't have it any longer).

3rd UPDATE: so I DELETED the NUnit test project (again) and re-created it and left it dirt-simple (just whatever VS2022 creates on open) and it debugs! Now to start adding code and find out what breaks it!

Thoughts?

TIA,


Solution

  • So, there's nothing that caused debugging to not work. After deleting the NUnit test project (for the third time) and re-creating the tests (and oneTimeStartup code) from scratch again, the NUnit tests debug (and breakpoints stop) and there's no error saying some project guid could not be found. Go figure.

    So, if this is happening to you, you're not crazy. Delete and recreate the NUnit test project a few times (and take baby steps in implementing the tests) and it will eventually work!