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] Test Explorer Does Not Refresh Tests #252

Open
Tracked by #315
acgritt opened this issue Jul 13, 2023 · 25 comments
Open
Tracked by #315

[BUG] Test Explorer Does Not Refresh Tests #252

acgritt opened this issue Jul 13, 2023 · 25 comments
Assignees
Labels
area-test Test discovery, execution, debugging bug Something isn't working
Milestone

Comments

@acgritt
Copy link

acgritt commented Jul 13, 2023

Describe the Issue

This seems to be related to using a multi-root workspace as when commenting out the folders it works fine. When adding new Unit Tests and building the Test Explorer is not updating to reflect the new tests. I tried clicking the refresh button in Test Explorer and when I choose Run All Tests the tests do not appear to be run. If I reload the window in VS Code then when it loads the Test Explorer all the new tests show up.

Steps To Reproduce

  1. Workspace with Multi-Root Folder
  2. Unit Tests in Solution
  3. View Test Explorer
  4. Add Unit Tests

Expected Behavior

Adding new unit tests to the loaded solution should cause the Test Explorer to refresh and show the new tests.

Environment Information

No response

@acgritt acgritt added the bug Something isn't working label Jul 13, 2023
@f3
Copy link

f3 commented Jul 13, 2023

Git branch switching appears to suffer from the same issue (e.g., the "switched-to" branch includes new/removed unit tests).

@timheuer timheuer added the area-test Test discovery, execution, debugging label Jul 14, 2023
@timheuer
Copy link
Member

@acgritt do you perform a build after adding the new tests?

@SelfRef
Copy link

SelfRef commented Jul 14, 2023

Can confirm on my system. Multi-root (with .NET project in a second folder), I'm adding a new xUnit test file, then build/rebuild/cleanbuild/build+run/restart VSC and no matter what I do it doesn't show in Test Explorer. So I went to Visual Studio an it's shown right away (no build or anything). I run it. After that it's also shown in VS Code.

Is it like about some kind of tests cache that's only "big" VS can create?

VSCode 1.80.1, C# 2.0.249 (pre-rel), C# Dev Kit 0.3.2 (pre-rel)

@acgritt
Copy link
Author

acgritt commented Jul 14, 2023

@timheuer Yes, I do a build after adding the new tests. Nothing shows up in the explorer. Same happens if I remove or rename a test. The explorer doesn't change. When I "Reload Window" in VS Code or close and relaunch then the updated list of tests shows after I run the build again, but it is not refreshing the list without a heavier hand on the refresh process.

@ProTip
Copy link

ProTip commented Jul 16, 2023

I started running into this after re-structuring my solution a bit. It was showing duplicate tests, tests I removed, and was using the wrong path to look for the .dll.

A workaround was to remove the test store. If you check the solution explorer extension output it will tell you the location on startup:

~/.config/Code/User/workspaceStorage/1b7d19f80d33b5a0409cb3dab5cd9aa2/ms-dotnettools.csdevkit

In there I deleted the testStore folder and after re-starting VSCode everything came right.

@jpringle1
Copy link

jpringle1 commented Jul 18, 2023

A workaround was to remove the test store.

I am also having this problem, and can confirm that solution does work to a degree.
Unfortunately, I have to do this every time I create new test, which is not ideal.

Update:

The issue has now resolved itself, and now all i have to do to get the tests to show up is build the project. No idea what fixed this or how to reproduce the problem.

@ivanjx
Copy link

ivanjx commented Jul 28, 2023

i always need to use dotnet watch build on my test projects to make the tests appear correctly on the tests pane.

@joshuabrink
Copy link

I managed to resolve it by removing the bin path from my files.watcherExclude settings and reloading my vscode.

@LynxWall
Copy link

LynxWall commented Aug 6, 2023

I'm experiencing similar issues when changing the build target. Duplicate tests, errors trying to load invalid assembly, etc. The only way to resolve these issues is to delete the testStore under workspaceStorage.

@ProTip Thank you for posting that workaround, was getting very frustrated with bad tests until I found this.

@webreidi webreidi added this to the GA milestone Aug 16, 2023
@peterwald
Copy link
Member

@ivanjx @LynxWall @acgritt @jpringle1 @ProTip

Can you give me an idea of what the structure of your multi-root workspace looks like? Do you have all of your C# code & tests in one root, and other languages in the other roots? (i.e. javascript, web assets, etc...)

Or are you creating a solution that somehow spans C# projects across multiple workspace roots?

@acgritt
Copy link
Author

acgritt commented Aug 23, 2023

@peterwald
Generally I have the following:

  • Root Folder
    • Workspace File
    • .gitignore
    • etc
    • src
      • Solution File
      • Code
    • docs
      • documentation files

The workspace is set to display the src folder as Source and docs as Documentation at the root. Sometimes, when working with a dotnet angular project I also have Angular as a folder that points to the client folder inside the API project. When I click the refresh button to refresh the tests the status line that appears just blips and the logs show nothing as having been done. It isn't until I reload the VS Code window that the new tests show up.

@peterwald
Copy link
Member

A fix has been merged and will be available in the next pre-release build.

@tatejones
Copy link

I am assuming this fix has been released in a pre-release build. I am running C# Dev Kit v0.5.150 and I am still experiencing the following issues.

  1. New tests not detected when clicking the refresh
  2. Changes to test code are not reflected in the test outcome. The old test logic continues to be executed.

Executing
dotnet watch test --project /csproject
works fine.
Even after that the test explorer still continues to execute the old code. How is that possible? Only after performing a dotnet clean will the test explorer will start executing the correct code.

The layout is:
Root:

  • Workspace file
  • Solution file (references projects)
  • Project A
    • cs project file
    • source files
  • Project B
    • cs project file
    • source files

@tatejones
Copy link

It looks like the test explorer is creating binaries in bin/Debug/net6.0//...
But the VSTest Adapter v2.5.0.1+5ebf84cd75 (64-bit .NET 6.0.22) is looking for binaries in the bin/x64/Debug/net6.0/

bin/Debug vs bin/x64/Debug

@peterwald
Copy link
Member

@tatejones C# Dev Kit v0.5.150 should include the fix I referenced above.

The test explorer invokes the build command provided by the solution/project, it doesn't do anything special on its own. This should be the same as right clicking the Project or Solution node in the Solution Explorer section of the file pane and selecting build from there.

When you say...

VSTest Adapter v2.5.0.1+5ebf84cd75 (64-bit .NET 6.0.22) is looking for binaries in the bin/x64/Debug/net6.0/

What does that mean? Which VSTest Adapter? Are you looking at what dotnet test does on the command line?

@tatejones
Copy link

tatejones commented Oct 8, 2023 via email

@tatejones
Copy link

tatejones commented Oct 8, 2023

When it is discovering tests the log indicates it is searching through the binaries that have a platform in the path.

In Summary:

  1. The build triggered via the Test Explorer doesn't have the platform in the binary path
  2. The build triggered via the Solution Explorer does have the platform in the path
  3. The VSTest Adapter is using the builds generated by the Solution Explorer build.

Hence the VSTest Adapter never see a new build unless a build is manually triggered by the Solution Explorer or via the command line that includes the platform. The trigger that builds the binaries from the Test Explorer needs to use the same build instructions that of the Solution Explorer.

@thegoatherder
Copy link

FWIW I am seeing the same issue on a node.js project. New tests incoming from a git pull are not detected in Test Explorer, nor do they have the test controls (run, debug) in the gutter area.

@peterwald
Copy link
Member

FWIW I am seeing the same issue on a node.js project. New tests incoming from a git pull are not detected in Test Explorer, nor do they have the test controls (run, debug) in the gutter area.

C# Dev Kit only supports C# projects. A node.js extension for VS Code should be able to help with node.js tests.

@tatejones
Copy link

tatejones commented Nov 10, 2023

The solution for me was to introduce another platform. Originally I had only x64 for Release and Debug. The test adapter was always specifying a platform (project level?), hence was missing the build that didn't have a platform. Once I added another platform like "AnyCPU" the build finally added the platform and then the test adapter picked it up.

According to the docs.
"If a project configuration doesn't specify a platform or specifies just one platform, then a solution configuration whose name matches that of the new project configuration is either found or added. The default name of this solution configuration does not include a platform name; it takes the form < project configuration name >."

"If a project supports multiple platforms, a solution configuration is either found or added for each supported platform. The name of each solution configuration includes both the project configuration name and the platform name, and has the form < project configuration name > < platform name >."

Understand build configurations

@QuintinWillison
Copy link

QuintinWillison commented Nov 15, 2023

Refresh button does nothing for me. I have to restart VS Code to get new tests, every time I add a new one. 😞
We have a single root solution, with multiple projects, pretty standard.
Visual Studio handles it fine.
C# .NET 7.

@tengl
Copy link

tengl commented Jan 15, 2024

I have the same issue. I need to do CTRL+SHIFT+P and run Developer: Reload Window in order to get new tests in the Test Explorer.

I've configured the outputs from build to end up in the artifacts directory using the Directory.Build.props file in the root directory.

<Project>
  <PropertyGroup>
    <BaseOutputPath>$(MSBuildThisFileDirectory)artifacts\$(MSBuildProjectName)\bin</BaseOutputPath>
    <BaseIntermediateOutputPath>$(MSBuildThisFileDirectory)artifacts\$(MSBuildProjectName)\obj</BaseIntermediateOutputPath>
  </PropertyGroup>
</Project>

I have two solution (.sln) files in the root directory, one of them is default in .vscode/settings.json.

{
  "dotnet.defaultSolution": "Main.sln"
}

All code is in the src directory and tests in the tests directory. All projects are .Net 8. OS is Pop_OS!

About VS Code

Version: 1.85.1
Commit: 0ee08df0cf4527e40edc9aa28f4b5bd38bbff2b2
Date: 2023-12-13T09:47:11.635Z
Electron: 25.9.7
ElectronBuildId: 25551756
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Linux x64 6.6.6-76060606-generic

@tengl
Copy link

tengl commented Jan 15, 2024

The solution for me was to introduce another platform. Originally I had only x64 for Release and Debug. The test adapter was always specifying a platform (project level?), hence was missing the build that didn't have a platform. Once I added another platform like "AnyCPU" the build finally added the platform and then the test adapter picked it up.

According to the docs. "If a project configuration doesn't specify a platform or specifies just one platform, then a solution configuration whose name matches that of the new project configuration is either found or added. The default name of this solution configuration does not include a platform name; it takes the form < project configuration name >."

"If a project supports multiple platforms, a solution configuration is either found or added for each supported platform. The name of each solution configuration includes both the project configuration name and the platform name, and has the form < project configuration name > < platform name >."

Understand build configurations

I can also confirm that changing Directory.Build.props file to include AnyCPU in the path fixes the issue, the refresh button works now.

<Project>
  <PropertyGroup>
    <BaseOutputPath>$(MSBuildThisFileDirectory)artifacts\$(MSBuildProjectName)\bin\AnyCPU</BaseOutputPath>
    <BaseIntermediateOutputPath>$(MSBuildThisFileDirectory)artifacts\$(MSBuildProjectName)\obj\AnyCPU</BaseIntermediateOutputPath>
  </PropertyGroup>
</Project>

None of my projects targets any specific platform. Here is an example from a .csproj file.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <InternalsVisibleTo Include="$(AssemblyName).Tests" />
  </ItemGroup>

</Project>

@hutch120
Copy link

Took a while to figure this out, but one of my devs picked a specific csproj file when the solution first loaded in vscode. From then on it would only load tests for that project. We were able to fix this by deleting the cache output in the C# Dev Kit log. Although thinking about it, we might have been able to fix this by adding the additional projects to the solution explorer.

So, the dirty fix is to find the path to the C# Dev Kit cache in the in VSCode Output container/tab panel and delete the cache.

Looks something like this:
c:\Users\[username]\AppData\Roaming\Code\User\workspaceStorage\[GUID]\ms-dotnettools.csdevkit

Then, reload VSCode, and when the popup to select the project appears, select the solution instead of a specific project.

The Test explorer should then try to find tests in all the projects.

References:

@chrisdel101
Copy link

I've been using tests all day and they just stopped working. This has happened before many times. Restarting, deleting bin, rebuilding, cleaning...nothing works, Strangely enough I tried Window Reload (read about it above) and this fixed it, at least it fixed it right now. This issue is very derailing.

@AbhitejJohn
Copy link

Thanks for sharing your feedback folks. I'm re-opening this issue so we can take another look at why this is as flaky. Based on the comments here, it might be tied to this issue: #996 , we've been tracking with the filewatcher API in VSCode. The workaround there was to delete the bin+obj folders on all the projects, reopen vscode and trigger a build. That's a little on the heavy-handed side compared to the window reload workaround posted earlier. However tagging @ocallesp on this so we can investigate what is happening here and verify if it is the same problem as the one linked.

If anyone has a sharable repro that could help us track this down, that would be very much appreciated as well.

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 bug Something isn't working
Projects
None yet
Development

No branches or pull requests