Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Testing: MSTest: .NET8 Tests projects that compiles fine are neither visible in Test Explorer, nor runnable #996

Closed
omatrot opened this issue Mar 14, 2024 · 16 comments
Assignees
Labels
area-test Test discovery, execution, debugging area-vscode bug Something isn't working mac MacOS
Milestone

Comments

@omatrot
Copy link

omatrot commented Mar 14, 2024

Describe the Issue

I have a solution with multiple tests projects, but some of them are not visible in Test Explorer.
The test methods in the concerned projects are not runnable because there is no green play button.
I know that the project needs to compile, and be compiled to have something to run.
In my case, all the projects compiles correctly, by only some of them are discovered.
Sometimes, I have been able to solve the problem by removing recursively the obj/bin directory of the project and its own project references, then rebuilding the test project. Until now it worked. But not anymore.

The projects have been upgraded in place with the assistant from .NET 4.7.1 to .NET 8.

Steps To Reproduce

I am running VS Code, Insider version, on a M1 Mac.
I have absolutely no idea if I would be able to reproduce the problem by creating new solution/projects from scratch.
If I add new test projects to my current solution and build them, they are discovered. So this is clearly a problem with some of the project themselves.

I have tried to replace the project content from a non working project with the content of one that works but it doesn't solve the problem.

Expected Behavior

Of course, the Tests should be discovered.

Environment Information

  • OS: macOS Sonoma 14.3.1
  • C# Dev Kit v1.5.4 (pre-release)
    -VS Code Version: 1.88.0-insider (Universal)
    Commit: 99a19815253d91900be5ec1016e0ecc7cc9a6950
    Date: 2024-03-14T05:50:25.208Z
    Electron: 28.2.6
    ElectronBuildId: 27476517
    Chromium: 120.0.6099.291
    Node.js: 18.18.2
    V8: 12.0.267.19-electron.0
    OS: Darwin arm64 23.3.0
@omatrot omatrot added the bug Something isn't working label Mar 14, 2024
@arunchndr arunchndr added the area-test Test discovery, execution, debugging label Mar 18, 2024
@AbhitejJohn
Copy link

@omatrot : Thanks for letting us know. I'm guessing its not really possible for you to share your solution publicly. Any chance you could share with us the contents of the pane - "Output -> C# Dev Kit - Test Explorer".

Also the contents of one of your test project file that does not work would be useful as well. I'm primarily interested in the package references this project has.

@omatrot
Copy link
Author

omatrot commented Mar 20, 2024

Sorry for the delay, the problem vanished on my MacBook...
But, I have switched to my iMac, no tests are visible.
Here is the output of the C# Dev Kit - Test Explorer Output (Some parts are in French, sorry):

Created Test Controller
Utilisation de vstest à partir du SDK dotnet dans [/usr/local/share/dotnet/sdk/8.0.100].
Initialized Test Explorer Server [45656]
Test Store Folder: /Users/oliviermatrot/Library/Application Support/Code - Insiders/User/workspaceStorage/d6565803bf63dc5ce5492de9d48b1bd9/ms-dotnettools.csdevkit
Magasin de données de test ouvert en 0,032 s.
Initialized project system provider.
4 projects added, 0 changed, 0 removed.
Scheduling discovery: /Users/oliviermatrot/Documents/SC/Product/SC.TM.Core.Test/bin/Debug/net8.0/SC.TM.Core.Test.dll [0]
Scheduling discovery: /Users/oliviermatrot/Documents/SC/Product/SC.TM.Labs.Test/bin/Debug/net8.0/SC.TM.Labs.Test.dll [0]
Scheduling discovery: /Users/oliviermatrot/Documents/SC/Product/SC.TM.Agent.Test/bin/Debug/net8.0/SC.TM.Agent.Test.dll [0]
Scheduling discovery: /Users/oliviermatrot/Documents/SC/Product/SC.TM.ResumeParser.test/bin/Debug/net8.0/SC.TM.ResumeParser.test.dll [0]
0 projects added, 0 changed, 0 removed.

Below is a .csproj file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <SccProjectName>SAK</SccProjectName>
    <SccLocalPath>SAK</SccLocalPath>
    <SccAuxPath>SAK</SccAuxPath>
    <SccProvider>SAK</SccProvider>
  </PropertyGroup>
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <!--<RuntimeIdentifier>osx-arm64</RuntimeIdentifier>-->
  </PropertyGroup>
  <ItemGroup>
    <EmbeddedResource Include="Resources\smiley-green.png" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\SC.TM.Core\SC.TM.Core.csproj" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
    <PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
    <PackageReference Include="EntityFramework" Version="6.4.4" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.*" />
    <PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
    <PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
    <PackageReference Include="SendGrid.SmtpApi" Version="1.4.6" />
  </ItemGroup>
  <ItemGroup>
   <None Remove="appsettings.json" />
 </ItemGroup>
 <ItemGroup>
   <Content Include="appsettings.json">
     <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
   </Content>
 </ItemGroup>
  <Target Name="CopyAppConfig" AfterTargets="Build" DependsOnTargets="Build">
    <CreateItem Include="$(OutputPath)$(AssemblyName).dll.config">
        <Output TaskParameter="Include" ItemName="FilesToCopy" />
    </CreateItem>
    <Copy SourceFiles="@(FilesToCopy)" DestinationFiles="$(OutputPath)testhost.dll.config" />
  </Target>
</Project>

@omatrot
Copy link
Author

omatrot commented Mar 20, 2024

By contrast, here is the output from the C# Dev Kit - Test Exploreroutput on my MacBook:

Created Test Controller
Using vstest from dotnet sdk in [/usr/local/share/dotnet/sdk/8.0.201].
Initialized Test Explorer Server [71175]
Test Store Folder: /Users/oliviermatrot/Library/Application Support/Code - Insiders/User/workspaceStorage/8249bb5b498661477643911855b0189d/ms-dotnettools.csdevkit
Test data store opened in 0.055 sec.
Initialized project system provider.
5 projects added, 0 changed, 0 removed.
0 projects added, 0 changed, 0 removed.
Scheduling discovery: /Users/oliviermatrot/Documents/SC/Product/SC.TM.Core.Test/bin/Debug/net8.0/SC.TM.Core.Test.dll [1710423943398]
Scheduling discovery: /Users/oliviermatrot/Documents/SC/Product/SC.TM.SmartTag.Test/bin/Debug/net8.0/SC.TM.SmartTag.Test.dll [1710851659284]
Scheduling discovery: /Users/oliviermatrot/Documents/SC/Product/SC.TM.Locality.Test/bin/Debug/net8.0/SC.TM.Locality.Test.dll [1710434169227]
Scheduling discovery: /Users/oliviermatrot/Documents/SC/Product/SC.TM.ResumeParser.test/bin/Debug/net8.0/SC.TM.ResumeParser.test.dll [1710946431558]
Scheduling discovery: /Users/oliviermatrot/Documents/SC/Product/SC.TM.Analytics.Test/bin/Debug/net8.0/SC.TM.Analytics.Test.dll [1710799182520]
========== Starting test discovery ==========
154 tests discovered from /Users/oliviermatrot/Documents/SC/Product/SC.TM.Locality.Test/bin/Debug/net8.0/SC.TM.Locality.Test.dll;/Users/oliviermatrot/Documents/SC/Product/SC.TM.Analytics.Test/bin/Debug/net8.0/SC.TM.Analytics.Test.dll;/Users/oliviermatrot/Documents/SC/Product/SC.TM.ResumeParser.test/bin/Debug/net8.0/SC.TM.ResumeParser.test.dll;/Users/oliviermatrot/Documents/SC/Product/SC.TM.Core.Test/bin/Debug/net8.0/SC.TM.Core.Test.dll;/Users/oliviermatrot/Documents/SC/Product/SC.TM.SmartTag.Test/bin/Debug/net8.0/SC.TM.SmartTag.Test.dll in 1669.9793 ms
========== Test discovery finished: 154 Tests found in 1.7 sec ==========

@ocallesp ocallesp added the mac MacOS label Mar 22, 2024
@ocallesp
Copy link
Member

ocallesp commented Mar 22, 2024

Sorry for the delay, the problem vanished on my MacBook... But, I have switched to my iMac, no tests are visible. Here is the output of the C# Dev Kit - Test Explorer Output (Some parts are in French, sorry):

Created Test Controller
Utilisation de vstest à partir du SDK dotnet dans [/usr/local/share/dotnet/sdk/8.0.100].
Initialized Test Explorer Server [45656]
Test Store Folder: /Users/oliviermatrot/Library/Application Support/Code - Insiders/User/workspaceStorage/d6565803bf63dc5ce5492de9d48b1bd9/ms-dotnettools.csdevkit
Magasin de données de test ouvert en 0,032 s.
Initialized project system provider.
4 projects added, 0 changed, 0 removed.
Scheduling discovery: /Users/oliviermatrot/Documents/SC/Product/SC.TM.Core.Test/bin/Debug/net8.0/SC.TM.Core.Test.dll [0]
Scheduling discovery: /Users/oliviermatrot/Documents/SC/Product/SC.TM.Labs.Test/bin/Debug/net8.0/SC.TM.Labs.Test.dll [0]
Scheduling discovery: /Users/oliviermatrot/Documents/SC/Product/SC.TM.Agent.Test/bin/Debug/net8.0/SC.TM.Agent.Test.dll [0]
Scheduling discovery: /Users/oliviermatrot/Documents/SC/Product/SC.TM.ResumeParser.test/bin/Debug/net8.0/SC.TM.ResumeParser.test.dll [0]
0 projects added, 0 changed, 0 removed.

Below is a .csproj file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <SccProjectName>SAK</SccProjectName>
    <SccLocalPath>SAK</SccLocalPath>
    <SccAuxPath>SAK</SccAuxPath>
    <SccProvider>SAK</SccProvider>
  </PropertyGroup>
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <!--<RuntimeIdentifier>osx-arm64</RuntimeIdentifier>-->
  </PropertyGroup>
  <ItemGroup>
    <EmbeddedResource Include="Resources\smiley-green.png" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\SC.TM.Core\SC.TM.Core.csproj" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
    <PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
    <PackageReference Include="EntityFramework" Version="6.4.4" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.*" />
    <PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
    <PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
    <PackageReference Include="SendGrid.SmtpApi" Version="1.4.6" />
  </ItemGroup>
  <ItemGroup>
   <None Remove="appsettings.json" />
 </ItemGroup>
 <ItemGroup>
   <Content Include="appsettings.json">
     <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
   </Content>
 </ItemGroup>
  <Target Name="CopyAppConfig" AfterTargets="Build" DependsOnTargets="Build">
    <CreateItem Include="$(OutputPath)$(AssemblyName).dll.config">
        <Output TaskParameter="Include" ItemName="FilesToCopy" />
    </CreateItem>
    <Copy SourceFiles="@(FilesToCopy)" DestinationFiles="$(OutputPath)testhost.dll.config" />
  </Target>
</Project>

Hi,

Is the same project opened in two different machines, but in one machine it works and in the other doesn't ?

is this a log of a repro?
If yes, it looks like 'test discovery' was not executed. This might be the issue.

To have more context, how many projects are in total ?
In see "4 projects added, 0 changed, 0 removed.", but I have no idea how many are missing.

For the project having the issue, was the dll generated in the output folder ?

@omatrot
Copy link
Author

omatrot commented Mar 25, 2024

Is the same project opened in two different machines, but in one machine it works and in the other doesn't ?

Yes it was, the tests that weren't visible in the test pane last friday, are this morning after a VS Code restart, tied to an update, and a solution rebuild.

is this a log of a repro?

Yes

To have more context, how many projects are in total ?

10 test projects, 10 library projects. 1 library has a corresponding unit test project.

For the project having the issue, was the dll generated in the output folder ?

Yes.

Copy link

This issue has been marked as stale after 14 days of inactivity. @AbhitejJohn, could you please take a look?

@ocallesp ocallesp self-assigned this Apr 2, 2024
@ocallesp
Copy link
Member

ocallesp commented Apr 2, 2024

I am taking a look at this issue. Will provide updates during the week.

@peterwald peterwald added this to the June2024 milestone Apr 30, 2024
@LazerFX
Copy link

LazerFX commented Jun 21, 2024

I had this issue, and ended up dropping back to SDK v7 in order to use the dev kit test explorer. At that point, I started getting
Scheduling discovery ...
lines appearing in my C# Dev Kit - Test Explorer window. I'll be following along with interest in the results of this investigation.

@wjrogers
Copy link

I had the same problem this morning working in Ubuntu WSL via the WSL remote extension. Only 3/5 test projects in my solution appeared in Test Explorer. The Output pane had a "Scheduling discovery:" message for all 5, but 2 of them never ran. I tried deleting all build artifacts and restarting vscode, and I tried updating the dotnet SDK, but neither changed the outcome.

Then, I tried updating the NuGet dependencies of my test projects and restarting vscode, and all 5 projects were correctly discovered.

  • GitHubActionsTestLogger from 2.3.3 to 2.4.1
  • Microsoft.NET.Test.Sdk from 17.9.0 to 17.10.0
  • xunit from 2.8.0 to 2.8.1
  • xunit.runner.visualstudio from 2.8.0 to 2.8.1

Hope this helps track down the problem.

@LazerFX
Copy link

LazerFX commented Jun 28, 2024

I've since moved to a different laptop and it's worked flawlessly on exactly the same solution. The main difference is that the laptop is significantly more performant (16GB of ram, and a 12-core CPU rather than a 4 core)... this leads me to suspect this is some form of time-out issue, as it was slightly intermittent in the first place.

@AbhitejJohn AbhitejJohn modified the milestones: June2024, July2024 Jul 19, 2024
@ocallesp
Copy link
Member

Can someone confirm if the 'C# Dev Kit - Test Explorer' log is showing all the existing test projects ?

For example, the log should display:
"N projects added, 0 changed, 0 removed"

It seems some test projects are not being discovered.

@ocallesp
Copy link
Member

I kind of reproed this bug. I deleted the bin and obj folder of each of the projects, re-open the solution in vs code insider and do a build. This detected all the tests projects.

@ocallesp
Copy link
Member

This issue in Test Explorer was caused by a bug in the VS Code file watcher microsoft/vscode#220039

@ocallesp
Copy link
Member

@omatrot Does this issue only repro in VS Code Insider ?

@omatrot
Copy link
Author

omatrot commented Jan 14, 2025

That is a good question. Time has gone by, and I have moved to other priorities. I have no more issues with tests not being discovered for a long time. And I have only be using VS-Code Insider.

@ocallesp
Copy link
Member

Fixed in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-test Test discovery, execution, debugging area-vscode bug Something isn't working mac MacOS
Projects
None yet
Development

No branches or pull requests

7 participants