dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.83k stars 654 forks source link

Cannot debug Nunit Parametrized TestFixture #5695

Open user19958 opened 1 year ago

user19958 commented 1 year ago

Problem description

I downloaded example Parametrized TestFixture file from: Nunit Parametrized TestFixture and when i want to debug in VSCode it fails with exception System.ArgumentException: Selected argument cannot be null or empty. (Parameter 'tests'). When I run "dotnet test" from terminal test start without any issue.

Environment data

dotnet --info output: Host: Version: 6.0.16 Architecture: x64 Commit: 1e620a42e7

.NET SDKs installed: 3.1.426 [C:\Program Files\dotnet\sdk] 6.0.408 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] VS Code version: Version: 1.78.2 (user setup) Commit: b3e4e68a0bc097f0ae7907b217c1119af9e03435 Date: 2023-05-10T14:39:26.248Z Electron: 22.5.2 Chromium: 108.0.5359.215 Node.js: 16.17.1 V8: 10.8.168.25-electron.0 OS: Windows_NT x64 10.0.22621 Sandboxed: Yes C# Extension version:

OmniSharp log

    Starting OmniSharp on Windows 10.0.22621.0 (x64)
    Checking the 'DOTNET_ROOT' environment variable to find a .NET SDK
    Using the 'dotnet' on the PATH.
    DotNetPath set to dotnet
    Located 1 MSBuild instance(s)
        1: .NET Core SDK 6.0.408 17.3.2 - "C:\Program Files\dotnet\sdk\6.0.408\"
    Registered MSBuild instance: .NET Core SDK 6.0.408 17.3.2 - "C:\Program Files\dotnet\sdk\6.0.408\"
    Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
    Detecting Cake files in 'c:\Users\kolarik\Downloads\nunitTest\parametrizedNunit'.
    Did not find any Cake files
    No solution files found in 'c:\Users\kolarik\Downloads\nunitTest\parametrizedNunit'
    Queue project update for 'c:\Users\kolarik\Downloads\nunitTest\parametrizedNunit\parametrizedNunit.csproj'
    Detecting CSX files in 'c:\Users\kolarik\Downloads\nunitTest\parametrizedNunit'.
    Did not find any CSX files
    Configuration finished.
    Omnisharp server running using Stdio at location 'c:\Users\kolarik\Downloads\nunitTest\parametrizedNunit' on host 9700.
    Loading project: c:\Users\kolarik\Downloads\nunitTest\parametrizedNunit\parametrizedNunit.csproj
    Successfully loaded project file 'c:\Users\kolarik\Downloads\nunitTest\parametrizedNunit\parametrizedNunit.csproj'.
    Adding project 'c:\Users\kolarik\Downloads\nunitTest\parametrizedNunit\parametrizedNunit.csproj'
    Update project: parametrizedNunit

Received response for /v2/getcodeactions but could not find request. Received response for /v2/gotodefinition but could not find request.

    read: {"MessageType":"TestSession.Connected","Payload":null}
    read: {"MessageType":"ProtocolVersion","Payload":1}
    Debug session started.
    ************ Request ************

{ "Type": "request", "Seq": 81, "Command": "/v2/debugtest/getstartinfo", "Arguments": { "FileName": "c:\Users\kolarik\Downloads\nunitTest\parametrizedNunit\UnitTest1.cs", "MethodName": "parametrizedNunit.ParameterizedTestFixture.TestInequality", "TestFrameworkName": "nunit", "TargetFrameworkVersion": ".NETCoreApp,Version=v6.0", "NoBuild": false } }

    ************  Response (4187.5981ms) ************ 

{ "Request_seq": 81, "Command": "/v2/debugtest/getstartinfo", "Running": true, "Success": false, "Message": "\"System.NullReferenceException: Object reference not set to an instance of an object.\r\n at OmniSharp.DotNetTest.VSTestManager.DebugGetStartInfoAsync(String[] methodNames, String runSettings, String testFrameworkName, String targetFrameworkVersion, CancellationToken cancellationToken) in D:\\a\\1\\s\\src\\OmniSharp.DotNetTest\\VSTestManager.cs:line 170\r\n at OmniSharp.Endpoint.EndpointHandler2.GetFirstNotEmptyResponseFromHandlers(ExportHandler2[] handlers, TRequest request) in D:\\a\\1\\s\\src\\OmniSharp.Host\\Endpoint\\EndpointHandler.cs:line 217\r\n at OmniSharp.Endpoint.EndpointHandler2.HandleRequestForLanguage(String language, TRequest request, RequestPacket packet) in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Host\\\\Endpoint\\\\EndpointHandler.cs:line 233\\r\\n at OmniSharp.Endpoint.EndpointHandler2.Process(RequestPacket packet, LanguageModel model, JToken requestObject) in D:\\a\\1\\s\\src\\OmniSharp.Host\\Endpoint\\EndpointHandler.cs:line 142\r\n at OmniSharp.Stdio.Host.HandleRequest(String json, ILogger logger) in D:\\a\\1\\s\\src\\OmniSharp.Stdio\\Host.cs:line 258\"", "Body": null, "Seq": 284, "Type": "response"

.NET Test log

NUnit Adapter 4.2.0.0: Test discovery starting NUnit Adapter 4.2.0.0: Test discovery complete System.ArgumentException: Selected argument cannot be null or empty.. (Parameter 'tests') at Microsoft.VisualStudio.TestPlatform.ObjectModel.ValidateArg.NotNullOrEmpty[T](IEnumerable1 arg, String parameterName) at Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.TestRunCriteria..ctor(IEnumerable1 tests, Int64 frequencyOfRunStatsChangeEvent, Boolean keepAlive, String testSettings, TimeSpan runStatsChangeEventTimeout, ITestHostLauncher testHostLauncher, TestSessionInfo testSessionInfo, Boolean debugEnabledForTestSession) at Microsoft.VisualStudio.TestPlatform.CommandLine.TestPlatformHelpers.TestRequestManager.RunTests(TestRunRequestPayload testRunRequestPayload, ITestHostLauncher3 testHostLauncher, ITestRunEventsRegistrar testRunEventsRegistrar, ProtocolConfig protocolConfig) at Microsoft.VisualStudio.TestPlatform.Client.DesignMode.DesignModeClient.<>c__DisplayClass23_0.b__0()

Steps to reproduce

  1. Download this exmaple project parametrizedNunit.zip
  2. Open in VSCode
  3. Run dotnet restore / dotnet build
  4. Try to debug some test

Expected behavior

Debug mode is stared

Actual behavior

System.ArgumentException: Selected argument cannot be null or empty.. (Parameter 'tests') is shown.

IlIlIllIllI commented 1 year ago

I've been having this problem on and off for some time now, only with the TestCaseSource NUnit test attribute.

Sometimes it works, sometimes it doesn't, no idea why.

moteus commented 10 months ago

I have the same issues with the new 2.x version. And in my case problem with the SetName call for the TestCaseData

private static IEnumerable TestCases()
{
    yield return new TestCaseData(1, 2, 3).SetName("Some test case");
}

[TestCaseSource(nameof(TestCases))]
public async Task TestCase(int param1, int param2, int param3)
{
    ...
}

So if I remove the .SetName("Some test case"); VSCode can run the TestCase function.