Skip to content

VSCode Test Explorer - unit test execution is slow/problematic because they run at the workspace level not crate

Closed

Description

Invoking a single unit test from the Test Explorer or keyboard shortcut will build the entire workspace and tests are processed in every workspace member which causes several problems:

  • unit tests cannot run if any crate in a workspace does not compile even though they are not relevant dependencies
  • running a unit test builds unrelated crates on every/any code change
  • unit tests are referenced by their name within a crate which can collide between between workspace members
    • e.g. two clis in a workspace with a main.rs containing mod tests :: test_arg_parsing
    • this means the wrong test is run / results reported against the wrong test etc.
  • even without any code changes:
    • unit tests run much slower because the runner tries to run the test in every single workspace member
      • rust-analyzer takes multiple seconds to run a test that cargo test completes in milliseconds
    • there is excess message spam in the test output because it contains every warning/lint and build message from the entire workspace

Example test output trying to execute one unit test where rust-anlayzer tries to run a test in every single workspace member which I have anonymised as <crate>:

Running unittests src/main.rs (target/debug/deps/<crate>-d7d1af8a1ff77b91)
Running unittests src/main.rs (target/debug/deps/<crate>-8f1e321689784723)
Running unittests src/main.rs (target/debug/deps/<crate>-630fa9cd06696d27)
Running unittests src/main.rs (target/debug/deps/<crate>-94ccfaaf3259bc9c)
Running unittests src/main.rs (target/debug/deps/<crate>-03afafaad8d31312)
Running unittests src/lib.rs (target/debug/deps/<crate>-6ec99e8e97e196c7)
Running unittests src/lib.rs (target/debug/deps/<crate>-1294bbf4f9a3a681)
Running unittests src/main.rs (target/debug/deps/<crate>-a0bf89f18085b65e)
Running unittests src/main.rs (target/debug/deps/<crate>-c2d90a1bf651628e)
...
etc.
Doc-tests <crate>
Doc-tests <crate>
Doc-tests <crate>
Doc-tests <crate>
Doc-tests <crate>
Doc-tests <crate>
Doc-tests <crate>
...
etc.

@HKalbasi I can see this relates to your changes here:

#17056

I have a PR that behaves as I expect which is to run tests on the crate in which they are defined and not at the workspace root but I don't know if this will cause other issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-test-explorerIssues related to the test explorer lsp extension and vscode test apiIssues related to the test explorer lsp extension and vscode test apiC-bugCategory: bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions