forcedotcom / salesforcedx-vscode

Salesforce Extensions for VS Code
https://developer.salesforce.com/tools/vscode
BSD 3-Clause "New" or "Revised" License
953 stars 406 forks source link

Apex Tests Sidebar includes non-existent Apex Test Classes #5539

Closed curtdrummond-cvmajesco closed 5 months ago

curtdrummond-cvmajesco commented 5 months ago

Summary

When viewing Apex Tests in the "Testing" sidebar, I see records for namespaced test classes (e.g. "namespace.MyTestClass"). These tests do not run, and attempting to run them (or run all tests) provides an error message:

11:54:36.671 Starting SFDX: Run Apex Tests

This class name's value is invalid: usal. Provide the name of an Apex class that has test methods.

I had previously created this namespace and packaged components in it, but this was done in a branch that was not merged to the branch I am currently using, and do not have a namespace defined in my sfdx-project.json file. I am using a fresh scratch Org.

Steps To Reproduce:

  1. Create a new scratch org
  2. Deploy my codebase to the org via sf project deploy start -d force-app/main
  3. Go to the "Testing" sidebar, and click the "refresh" button for Apex Tests

Expected result

Apex Tests listed in Testing Sidebar should include only those Apex test classes that are in my project that have been deployed to the Org.

Actual result

Apex Tests listed in Testing Sidebar include additional test classes that are not in my codebase. These appear to be duplicates of test classes that ARE in the codebase, but have namespaces prefixed, e.g. I will see both "TriggerHandler_Test" and "usal.TriggerHandler_Test" in the list of available Apex tests.

Additional information

image

Salesforce Extension Version in VS Code: v60.8.0

SFDX CLI Version: @salesforce/cli/2.36.8 win32-x64 node-v18.17.1

OS and version: Windows 10 Enterprise 10.0.19045 Build 19045

VS Code version: 1.88.1

peternhale commented 5 months ago

@curtdrummond-cvmajesco Would you mind running a find on your project in vscode and look for the string usal. Please ensure Files to include is empty.

curtdrummond-cvmajesco commented 5 months ago

Hi @peternhale , nothing relevant is found, only false positives (e.g. a bunch of hits on "Israel Standard Time (Asia/Jerusalem)", "causality", "PlatformStatusAlertEvent", but nothing related to the namespace.

peternhale commented 5 months ago

@curtdrummond-cvmajesco If you would like to try this to see if it clears the issue.

Shutdown vscode Remove folder <your project root>\.sfdx\tools\248 and its contents. Start vscode

Removing this folder will cause apex language server to reindex all apex artifacts in the workspace, so it might take a little longer to be ready.

curtdrummond-cvmajesco commented 5 months ago

Hi @peternhale , that did the trick -- thank you!

git2gus[bot] commented 5 months ago

This issue has been linked to a new work item: W-15518744

peternhale commented 5 months ago

Hi @curtdrummond-cvmajesco, I am glad you are up and running.

peternhale commented 5 months ago

@curtdrummond-cvmajesco I am trying to get a sense of the transitions you went through leading up to the test view being populated with the non-existent test classes/methods.

This is what I understand thus far:

Was vscode shutdown between the transition between branches?

curtdrummond-cvmajesco commented 5 months ago

Hi @peternhale,

Work started as an un-namespaced Unlocked Package. Project decision-makers requested a change to a namespaced Unlocked Package. I created a branch to test switching the project over, and created a couple Package Versions with the new namespace(s).

However, I wanted to wait until the next scheduled packaging to implement the namespace. So in the meantime, I switched back to the main branch and current feature branches and operated as normal.

This was all done in the same workspace. Transition between branches was done via the git switch command. I don't recall if I shutdown vscode in between the namespace branch and the next time I ran tests in one of the non-namespace branches, but once I realized that the list of tests included duplicate (namespaced) tests, I did try shutting down vscode and restarting it (a couple of times) before opening the issue.

As an update, in case it's useful or intereting, I have been doing a bit of work today with various branches with the namespace, and the test sidebar now once again shows some duplicated (and namespaced) test classes. It looks like a larger subset of my test classes than were originally present when I raised this issue.

peternhale commented 5 months ago

@curtdrummond-cvmajesco thanks for the additional clues.