vscode-csharp
vscode-csharp copied to clipboard
Cannot debug unit tests - Failed to start debugger: "System.NullReferenceException: Object reference not set to an instance of an object
Issue Description
The project I am working on is based on .net 5.0. It uses NUnit (3.12.0) and NUnit3TestAdapter (3.15.1) packages. This issue happens when I try to debug generic NUnit unit tests. It started recently and happens every time I try to click "Debug Test" link above generic unit test. Simple non-generic tests with and without parameters are working fine. I am using portable Visual Studio Code.
When I try to run such tests using "Run test" link, my tests won't run.
Steps to Reproduce
- Create simple test class.
- Create generic unit test using NUnit (look at example screenshots).
- Try to debug the test by clicking "Debug test"
Expected Behavior
I should be able to debug the test
Actual Behavior
I cannot debug the test
Logs
OmniSharp log
C# log
No logs here.
.NET Test Log
Environment information
VSCode version: 1.61.0-insider (1.60.2 too) C# Extension: 1.23.15
Mono Information
OmniSharp using built-in monoDotnet Information
.NET SDK (reflecting any global.json): Version: 5.0.203 Commit: 383637d63fRuntime Environment: OS Name: pop OS Version: 21.04 OS Platform: Linux RID: linux-x64 Base Path: [omitted]/5.0.203/
Host (useful for support): Version: 5.0.6 Commit: 478b2f8c0e
.NET SDKs installed: 3.1.115 [omitted] 5.0.203 [omitted]
.NET runtimes installed: Microsoft.AspNetCore.App 3.1.15 [omitted] Microsoft.AspNetCore.App 5.0.6 [omitted] Microsoft.NETCore.App 3.1.15 [omitted] Microsoft.NETCore.App 5.0.6 [omitted]
To install additional .NET runtimes or SDKs: https://aka.ms/dotnet-download
Visual Studio Code Extensions
Extension | Author | Version |
---|---|---|
csharp | ms-dotnettools | 1.23.15 |
vsc-community-material-theme | Equinusocio | 1.4.4 |
The reason for this is that omnisharp does not consider any Attributtes to run or debug Nunit Tests:
src/OmniSharp.DotNetTest/TestFrameworks/NUnitTestFramework.cs src/OmniSharp.DotNetTest/TestMethodPropertyProvider.cs
The Test Framework is "method-driven". The vscode extension tries to run and debug with the "method name", because that is how the codeLensProvider is implemented, instead, it should use the fully qualified name of the test.
fyi, you can list the tests with fully qualified names with:
dotnet vstest <path/to/test-project.dll> /ListFullyQualifiedTests /ListTestsTargetPath:test.txt
If you want to keep using omnisharp with nunit the way it is, I would recommend you to remove TestCase Attributes.. and create a Test method for each one of them.