microsoft / vscode-dotnettools

This is a feedback repository to capture issues logged for the C# Dev Kit and related extensions from Visual Studio Code
Other
207 stars 7 forks source link

[BUG] xUnit testing not working in a class when the only test is a Theory using MemberData #946

Open dibarbet opened 4 months ago

dibarbet commented 4 months ago

Describe the Issue

Originally filed by @neliason0 at https://github.com/dotnet/vscode-csharp/issues/6913#

Type: Bug

Issue Description

If an xUnit test class has only a Theory test using MemberData, testing does not work as expected. If you add a Theory test using InlineData, or a Fact test, then this issue does not occur.

Steps to Reproduce

Create an xUnit test where the only test is a Theory using MemberData. Run test.

Expected Behavior

Expect test to run, results to be reported by a green checkmark or a red x in the Testing panel. Expect the code window gutter to have the same indication beside the method declaration. Expect to be able to rerun the test using the gutter icon, or context menu.

Actual Behavior

No indication of the test result is indicated in the Testing panel. The icon is a small circle. The gutter icon in the code window dissappears. The option to run/debug tests dissappears from the context menu.

Sample Code:

public class MyDisappearingTestTest
{
    public static TheoryData<string, TimeSpan> TimeSpanTestData =>
    new()
    {
        {"1:00",new TimeSpan(1,0,0)},
        {"2:00",new TimeSpan(2,0,0)},
    };

    [Theory]
    [MemberData(nameof(TimeSpanTestData))]
    public void TheoryTestMethodData(string actual, TimeSpan expected)
    {
        var actualTimeSpan = TimeSpan.Parse(actual);
        Assert.Equal(expected, actualTimeSpan);
    }

    // [Theory]
    // [InlineData("1:00", "1:00")]
    // public void TheoryTestInline(string actual, string expected)
    // {        
    //     Assert.Equal(expected, actual);     
    // }

    // [Fact]
    // public void FactTest_Should()
    // {    
    //     Assert.True(true);
    // }
}

Logs

C# log

Post the output from Output-->C# here

C# LSP Trace Logs

Post the output from Output-->C# LSP Trace Logs here. Requires `dotnet.server.trace` to be set to `Trace`

Environment information

VSCode version: 1.86.2 C# Extension: 2.15.30 Using OmniSharp: false

Dotnet Information .NET SDK: Version: 8.0.100 Commit: 57efcf1350 Workload version: 8.0.100-manifests.6c33ef20 Runtime Environment: OS Name: Mac OS X OS Version: 14.1 OS Platform: Darwin RID: osx-arm64 Base Path: /usr/local/share/dotnet/sdk/8.0.100/ .NET workloads installed: Workload version: 8.0.100-manifests.6c33ef20 There are no installed workloads to display. Host: Version: 8.0.0 Architecture: arm64 Commit: 5535e31a71 .NET SDKs installed: 6.0.300 [/usr/local/share/dotnet/sdk] 7.0.400 [/usr/local/share/dotnet/sdk] 8.0.100 [/usr/local/share/dotnet/sdk] .NET runtimes installed: Microsoft.AspNetCore.App 6.0.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.10 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.10 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Other architectures found: None Environment variables: DOTNET_ROOT [/usr/local/share/dotnet/] global.json file: Not found Learn more: https://aka.ms/dotnet/info Download .NET: https://aka.ms/dotnet/download
Visual Studio Code Extensions |Extension|Author|Version|Folder Name| |---|---|---|---| |csdevkit|ms-dotnettools|1.3.10|ms-dotnettools.csdevkit-1.3.10-darwin-arm64| |csharp|ms-dotnettools|2.15.30|ms-dotnettools.csharp-2.15.30-darwin-arm64| |debugpy|ms-python|2024.0.0|ms-python.debugpy-2024.0.0-darwin-arm64| |dotnet-interactive-vscode|ms-dotnettools|1.0.5101020|ms-dotnettools.dotnet-interactive-vscode-1.0.5101020| |jupyter|ms-toolsai|2024.1.1|ms-toolsai.jupyter-2024.1.1-darwin-arm64| |jupyter-keymap|ms-toolsai|1.1.2|ms-toolsai.jupyter-keymap-1.1.2| |jupyter-renderers|ms-toolsai|1.0.17|ms-toolsai.jupyter-renderers-1.0.17| |php-debug|xdebug|1.34.0|xdebug.php-debug-1.34.0| |python|ms-python|2024.0.1|ms-python.python-2024.0.1| |rainbow-csv|mechatroner|3.11.0|mechatroner.rainbow-csv-3.11.0| |remote-explorer|ms-vscode|0.4.1|ms-vscode.remote-explorer-0.4.1| |remote-ssh|ms-vscode-remote|0.108.0|ms-vscode-remote.remote-ssh-0.108.0| |remote-ssh-edit|ms-vscode-remote|0.86.0|ms-vscode-remote.remote-ssh-edit-0.86.0| |roslynator|josefpihrt-vscode|4.10.0|josefpihrt-vscode.roslynator-4.10.0| |vscode-docker|ms-azuretools|1.28.0|ms-azuretools.vscode-docker-1.28.0| |vscode-dotnet-runtime|ms-dotnettools|2.0.1|ms-dotnettools.vscode-dotnet-runtime-2.0.1| |vscode-intelephense-client|bmewburn|1.10.2|bmewburn.vscode-intelephense-client-1.10.2| |vscode-jupyter-cell-tags|ms-toolsai|0.1.8|ms-toolsai.vscode-jupyter-cell-tags-0.1.8| |vscode-jupyter-slideshow|ms-toolsai|0.1.5|ms-toolsai.vscode-jupyter-slideshow-0.1.5| |vscode-pylance|ms-python|2024.2.1|ms-python.vscode-pylance-2024.2.1| |vscodeintellicode-csharp|ms-dotnettools|0.1.26|ms-dotnettools.vscodeintellicode-csharp-0.1.26-darwin-arm64| |vsliveshare|ms-vsliveshare|1.0.5905|ms-vsliveshare.vsliveshare-1.0.5905| |xml|DotJoshJohnson|2.5.1|dotjoshjohnson.xml-2.5.1|;

Extension version: 2.15.30 VS Code version: Code 1.86.2 (903b1e9d8990623e3d7da1df3d33db3e42d80eda, 2024-02-13T19:42:12.210Z) OS version: Darwin arm64 23.1.0 Modes:

System Info |Item|Value| |---|---| |CPUs|Apple M1 (8 x 24)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
webgpu: enabled| |Load (avg)|3, 2, 2| |Memory (System)|16.00GB (0.06GB free)| |Process Argv|--crash-reporter-id e0a1c241-08dd-40d0-bce0-8be750957fe9| |Screen Reader|no| |VM|0%|
A/B Experiments ``` vsliv368:30146709 vspor879:30202332 vspor708:30202333 vspor363:30204092 vscod805:30301674 binariesv615:30325510 vsaa593cf:30376535 py29gd2263:30899288 c4g48928:30535728 azure-dev_surveyone:30548225 a9j8j154:30646983 962ge761:30959799 pythongtdpath:30769146 welcomedialogc:30910334 pythonidxpt:30866567 pythonnoceb:30805159 asynctok:30898717 pythontestfixt:30902429 pythonregdiag2:30936856 pyreplss1:30897532 pythonmypyd1:30879173 pythoncet0:30885854 pythontbext0:30879054 dsvsc016:30899300 dsvsc017:30899301 dsvsc018:30899302 d6fi2104:30959263 pydisww1:30959800 edj9j583:30969295 fegfb526:30961430 7j2b6412:30969109 ```

Steps To Reproduce

No response

Expected Behavior

No response

Environment Information

No response

ocallesp commented 3 months ago

@ocallesp need to reproduce

ocallesp commented 2 months ago

I cannot repro this issue on a windows/mac machine in a xunit test project targeting net core 8.0

<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />

Extensions: C# Dev Kit v1.5.18 (pre-release) and release C# v2.23.15

CannotReproGithubIssue946

@dibarbet if you use this similar configuration I posted here, does it work on your machine ? I just want to know if this is specific for mac machines.