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] Unit Tests are not discovered in Test Explorer by C# Dev Kit in version 1.10.16 to 1.13.9 inclusive #1644

Closed
danbailey1000 opened this issue Nov 28, 2024 · 18 comments
Assignees
Labels
area-test Test discovery, execution, debugging bug Something isn't working
Milestone

Comments

@danbailey1000
Copy link

danbailey1000 commented Nov 28, 2024

Describe the Issue

Unit tests are not discovered by Test Explorer by C# Dev Kit version 1.10.16 to 1.13.9 inclusive

I have tried it with a very simple project with one unit test and the Test Explorer says "no tests have been found in this workspace yet".

namespace TestProject1;

namespace TestProject1;

[TestClass]
public class UnitTest1
{
    [TestMethod]
    public void TestMethod1()
    {
        Assert.IsTrue(true);
    }
}

Test Explorer works in extension version 1.9.55. All tests are discovered correctly with exactly the same project. I tested all versions and 1.9.55 worked.

Steps To Reproduce

In a windows 11 environment when opening a workspace with the attached project Test Explorer does not discover any testsdantest.zip

Expected Behavior

The test explorer should automatically discover unit tests

It works in extension version 1.9.55. All tests are discovered correctly

Environment Information

Windows 11
VS Code version 1.95.3
Extension version 1.10.16 to 1.13.9 inclusive

@danbailey1000 danbailey1000 added the bug Something isn't working label Nov 28, 2024
@danbailey1000 danbailey1000 changed the title Unit Tests are not discovered in Test Explorer in version 1.10.16 to 1.13.9 inclusive Unit Tests are not discovered in Test Explorer by C# Dev Kit in version 1.10.16 to 1.13.9 inclusive Nov 28, 2024
@danbailey1000 danbailey1000 changed the title Unit Tests are not discovered in Test Explorer by C# Dev Kit in version 1.10.16 to 1.13.9 inclusive [Bug] Unit Tests are not discovered in Test Explorer by C# Dev Kit in version 1.10.16 to 1.13.9 inclusive Nov 28, 2024
@danbailey1000 danbailey1000 changed the title [Bug] Unit Tests are not discovered in Test Explorer by C# Dev Kit in version 1.10.16 to 1.13.9 inclusive [BUG] Unit Tests are not discovered in Test Explorer by C# Dev Kit in version 1.10.16 to 1.13.9 inclusive Nov 28, 2024
@webreidi webreidi added the area-test Test discovery, execution, debugging label Dec 2, 2024
@ocallesp ocallesp self-assigned this Dec 3, 2024
@ocallesp
Copy link
Member

ocallesp commented Dec 3, 2024

Taking a look

@ocallesp
Copy link
Member

ocallesp commented Dec 3, 2024

@danbailey1000

I was unable to reproduce the issue.

In your case, was the build completed successfully?

  • If yes, could you share the output from the C# Dev Kit - Test Explorer?
  • If no, that might be the root cause of the issue.

@danbailey1000
Copy link
Author

@ocallesp
thanks for looking

The build is completed successfully. I tried this many times. dotnet build and also via the test explorer refresh button.

The only output from test explorer is that it did not discover any tests.

My guess this is some environmental issue on my primary laptop in combination with a defect. Something must have changed in C# Dev because the older version 1.9.55 works fine but as soon as I update the tests are not discovered. (I also did not reproduce on another computer). Perhaps the history of changes since 1.9.55 would reveal something suspicious. I see there have been fixes in the test explorer areas and perhaps on of these fixes caused the problem I am seeing. If you want to screenshare can also arrange something.

@ocallesp
Copy link
Member

ocallesp commented Dec 4, 2024

In the output C# Dev Kit - Test Explorer, do you see if SDK was resolved ? does it show if any project added ?

@AbhitejJohn AbhitejJohn added this to the Dec2024 milestone Dec 5, 2024
@tysonstewart
Copy link

I came looking for an issue to track the status and perhaps this one is it. I've been using this extension for perhaps 5 months or so and it never picks up a single test in a file. I always need to add at least one more test for them to show up in Test Explorer. Additionally, I've found that tests I add at the top of the file after I've already added a few do not show up without reloading the window.

I was previously on .NET 7 but recently updated to 8 and it has remained true. I am using a dev container based on dotnet:8.0-bookworm-slim and my machine is Mac if any of those things should be a factor.

@joaoopereira
Copy link

joaoopereira commented Jan 6, 2025

I had this issue today, and I did these steps to make it work:

  1. Close vscode
  2. Delete the content of C:\Users\[UserName]\AppData\Roaming\Code\User\workspaceStorage
  3. Open vscode
  4. Click on Test Explorer - Refresh Tests

UPDATE 08/01 - It worked, but it's not working anymore

@AbhitejJohn AbhitejJohn modified the milestones: Dec2024, Jan2025 Jan 8, 2025
@ocallesp
Copy link
Member

ocallesp commented Jan 15, 2025

@joaoopereira, do you have any steps to reproduce the issue, or could you share the output from the C# DevKit - Test Explorer? Also, I noticed the original issue was reported on Windows—are you encountering the same scenario now?

Here is a url to explain how to enable Diagnostic logs -> https://code.visualstudio.com/docs/csharp/cs-dev-kit-faq#_test-explorer

@ocallesp
Copy link
Member

ocallesp commented Jan 15, 2025

@danbailey1000 have you tried deleting the bin\ and obj\ folders in your repro project dantest.zip and rebuilding it ? Does that resolve the issue ? Do you still repro on latest version of C# Dev Kit ?

@gregorybleiker
Copy link

I have this with the latest versions as well. Diagnostics settings is not giving me anything. Clean lib test project created according to ms docs. Going back to 1.8 version of plugin helps.

@ocallesp
Copy link
Member

ocallesp commented Jan 21, 2025

@gregorybleiker are you encountering this issue in xUnit or MSTest? on windows ?

@gregorybleiker
Copy link

@ocallesp both

@gregorybleiker
Copy link

Windows 10

@ocallesp
Copy link
Member

In this thread, no logs have been posted yet, so I am trying to reproduce the original bug.

Could someone confirm if the logs you are seeing are similar to this:

Created Test Controller
Log verbosity: minimal
Using vstest from dotnet sdk in [C:\Program Files\dotnet\sdk\9.0.102].
Initialized Test Explorer Server [2600]
Test Store Folder: c:\Users\MyUser\AppData\Roaming\Code\User\workspaceStorage\0ca27759c40293c96da27a69851c1238\ms-dotnettools.csdevkit
Test data store opened in 0.025 sec.
Initialized project system provider.

instead of

Created Test Controller
Log verbosity: minimal
Using vstest from dotnet sdk in [C:\Program Files\dotnet\sdk\9.0.102].
Initialized Test Explorer Server [4632]
Test Store Folder: c:\Users\MyUser\AppData\Roaming\Code\User\workspaceStorage\0ca27759c40293c96da27a69851c1238\ms-dotnettools.csdevkit
Test data store opened in 0.057 sec.
Initialized project system provider.
1 projects added, 0 changed, 0 removed.
Scheduling discovery: C:\Users\MyUser\source\repos\dantest\dantest\TestProject1\bin\Debug\net8.0\TestProject1.dll [Last modified: 1/27/2025, 7:46:42 PM]
========== Starting test discovery ==========
========== Test discovery finished: 1 Tests found in 1 sec ==========
1 tests discovered from C:\Users\MyUser\source\repos\dantest\dantest\TestProject1\bin\Debug\net8.0\TestProject1.dll in 1023.4345 ms

In the bad scenario, it seems the logs are missing this line:
1 projects added, 0 changed, 0 removed.

If this matches your experience, it would suggest the issue occurs when no DLLs are generated from builds- specifically, when VS Code is opening the folder for the first time.

Could someone confirm if this is the case?

@gregorybleiker
Copy link

@ocallesp this is the output of the logs:

Created Test Controller
Log verbosity: diagnostic
[diag] C# Dev Kit version: 1.15.34
[diag] platform: win32 arch: x64
Using vstest from dotnet sdk in [C:\Program Files\dotnet\sdk\9.0.102].
Initialized Test Explorer Server [41896]
Test Store Folder: c:\tools\vscode\data\user-data\User\workspaceStorage\544d7c1be2c78fefc8d9358298eb5a0b\ms-dotnettools.csdevkit
Test data store opened in 0.010 sec.
[diag] Test Store loaded from persistance: No
Initialized project system provider.

@gregorybleiker
Copy link

gregorybleiker commented Jan 28, 2025

I have also pushed the repo I'm using to test: https://github.com/gregorybleiker/dotnet-unit-testing/
It's very close to the MS guide for unit testing in vs code

@ocallesp
Copy link
Member

@AbhitejJohn just to make you aware of this issue.
Based on the last confirmation from a user, this bug that is the same bug that is blocking the integration test.

We started a conversation with the Project System team to fix this.

@gregorybleiker
Copy link

@ocallesp additional things that might be perculiar about my environment:

  • we have company wide windows firewall settings (via GPO)
  • we are behind a proxy that is known to cause problems with certificates

@ocallesp
Copy link
Member

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

No branches or pull requests

7 participants