Skip to content

Warn if multiple tests run when trying to run a single test by name #2832

Closed

Description

@escamoteur

Have a look at this screencast
https://www.screencast.com/t/j0utedFnzL

We found out the reason is that there is another test with the same name further up the file

Versions (please complete the following information):

  • VS Code version: 1.49.1
  • Dart extension version: v3.14.1
  • Dart/Flutter SDK version:1.22.0

Activity

  1. DanTup commented on Sep 30, 2020

    @DanTup
    Member

    This is unfortunately a known limitation. I don't believe pub run test has any way to run a single instance of a test if it has the exact same name (including group) as another test.

    I don't think it's very common to have this, and they should both show up in the test tree (though trying to re-run either will re-run both), so hopefully it's easy to spot and correct.

  2. added this to the Backlog milestone on Sep 30, 2020
  3. added
    in testingRelates to test execution of Dart/Flutter tests for end users
    on Sep 30, 2020
  4. escamoteur commented on Sep 30, 2020

    @escamoteur
    Author

    Don't you think it would make sense to give a warning in such a case? especially as tests are often copied something like this can easily happen and the result is conpletely confusing

  5. DanTup commented on Sep 30, 2020

    @DanTup
    Member

    Yep, I do - but unfortunately it's not very simple to do reliably, as tests can be dynamic (include variable names, etc.).

    There's an open issue in package:test discussing some possible improvements in this area:

    dart-lang/test#1328

    And some related things here:

    dart-lang/test#1332

    Hopefully these will help improve some of these things here.

  6. DanTup commented on Dec 8, 2020

    @DanTup
    Member

    I've excluded when test names contain variables (since that's more tricky), but for the most common case we'll know show a warning at the end of a test run if we expected only a single test to run (that is, you're not running a group, there is exactly one test name, and it does not contain a $) but multiple did:

    Screenshot 2020-12-08 at 11 38 23

  7. modified the milestones: Backlog, v3.18.0 on Dec 8, 2020
  8. added
    is enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.
    and removed on Dec 8, 2020
  9. changed the title [-]if more than one test has the same name clicking on the debug or run link always executes the one further up[/-] [+]Warn if multiple tests run when trying to run a single test by name[/+] on Dec 8, 2020
  10. escamoteur commented on Dec 8, 2020

    @escamoteur
    Author

    I think that should be enough in most cased. will close this now.
    what happens if you click run on one of the tests that have a brother with the same name?

  11. reopened this on Dec 8, 2020
  12. DanTup commented on Dec 8, 2020

    @DanTup
    Member

    (Re-opening as I haven't landed the change yet, but it'll close when I do :-))

    what happens if you click run on one of the tests that have a brother with the same name?

    I'm not sure what you mean - isn't this the same case described above? Or do you mean a non-sibling test? That should work as expected, as the "test name" we construct when running from code lens is actually a full name of all of the groups prefixed to it. It's only if the complete name matches that this will trigger. This is similar to how if you have two tests named "foo" in different groups, running one of them doesn't run the other today already.

  13. escamoteur commented on Dec 8, 2020

    @escamoteur
    Author

    ah, I reread your comment about. I wasn't sure if it were possible that just one but the wrong test is executed.

  14. DanTup commented on Dec 8, 2020

    @DanTup
    Member

    It shouldn't be - we should always run the test that you wanted, but if there is another test with the exact same name, that may run too. All we do now is count how many tests ran, and if it's > 1 but we had run in a way that we expected only one (eg. a single test name) we'll show the warning.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    in testingRelates to test execution of Dart/Flutter tests for end usersis enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions