Skip to content

Run tests using line/col to support groups/test with dynamic names #4021

Closed

Description

@MiniSuperDev

Added by @DanTup:

Some test cases to ensure are handled:


Describe the bug
I have some functions to give a specific format to the descriptions of the groups and tests, like indentation, in this way it is easier to read them in the console, but when I execute a specific test, giving run in that group or test it tells me:

No tests match regular expression "^groupDescriptionFormatted\('group 1'\)".

To Reproduce
this is a minimal example:

import 'package:test/test.dart';

String groupDescriptionFormatted(String description) {
  return description;
}

String subGroupDescriptionFormatted(String description) {
  return '\n    $description';
}

void main() {
  group(
    groupDescriptionFormatted('group 1'),
    () {
      group(subGroupDescriptionFormatted('sub group 1'), () {
        test('test', () {
          expect(true, isTrue);
        });
      });
    },
  );
  group(
    groupDescriptionFormatted('group 2'),
    () {
      group(subGroupDescriptionFormatted('sub group 1'), () {
        test('test', () {
          expect(true, isTrue);
        });
      });
    },
  );
}

If you press run or debug on a specific group or test, you can see the error, an also in the testing tab you can see that the names are the function instead of the real test name.
image

If you press run or debug on main, or use the command run all tests, it runs normal but also in the testing tab keep the names are the function instead of the real test name, and now also the real tests names.

image

Thank you.

Please complete the following information:
Operating System and version: Windows 10
VS Code version: 1.68.0
Dart extension version: 3.42.0
Dart/Flutter SDK version: flutter 3.0.1

Activity

  1. DanTup commented on Jun 20, 2022

    @DanTup
    Member

    Currently there are some limitations because of how tests are run individually (by name). Without executing the tests, it's impossible for the extension to know what groupDescriptionFormatted('group 1') returns, so it's not possible to build a dart test` command that has the correct test name to run.

    However, once you've run the test file, you should be able to run the tests from the explorer, or from the test icons in the gutter, because the previous runs names would have been captured.

    package:test does now have some other ways we can run tests (such as by line number/column) which may allow us to handle this better, but it'll need some work to move over (and ensure we don't try to do it for older versions of package:test).

    I'll keep this issue open to track that, as it looks like there isn't an existing issue tracking it right now.

  2. added this to the On Deck milestone on Jun 20, 2022
  3. added
    is enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.
    in testingRelates to test execution of Dart/Flutter tests for end users
    and removed on Jun 20, 2022
  4. changed the title [-]When run an specific group or test where the description is got from a function, It Fails and get "No tests match regular expression"[/-] [+]Run tests using line/col to support groups/test with dynamic names[/+] on Jun 20, 2022
  5. jtdLab commented on Oct 2, 2022

    @jtdLab

    Will running single tests/groups with dynamic descriptions via vs code be possible with this?

  6. DanTup commented on Oct 3, 2022

    @DanTup
    Member

    @jtdLab I'm hoping so, but I haven't done much testing yet (and it may depend on the exact configuration of the test). If you have some specific tests in mind, you can try running them from the terminal using the line/col like:

    dart test "path/to/test.dart?line=10&col=2"
    

    Where line/col are where your test definitions are. If that runs them, then it should work here. If it doesn't work, please post an example and I can do some digging.

  7. jtdLab commented on Oct 3, 2022

    @jtdLab

    @DanTup im thinking about a scenario like this

    foo_test.dart

    // I want to run this test via the vs code Run | Debug (even though it has no description)
    rendersText(MyWidget(), text: 'Foo');

    my_shared_testing_library.dart

    @isTest
    void rendersText(Widget widget, {required String text}) {
      testWidgets('renders $text', (tester) async {
        // Some testing here
      });
    }

    Is this possible via line/col and not description?

  8. DanTup commented on Oct 3, 2022

    @DanTup
    Member

    @jtdLab I would hope/expect that to work. You can test it by running dart test foo_test.dart?line=1 (where 1 is the line it's on). I'm not sure how well we handle tests without names in the Test Runner tree though (when they are discovered from source).. we might need to fabricate a name (like "test on line 1") so there is some label for the tree node.

  9. jtdLab commented on Oct 3, 2022

    @jtdLab

    @DanTup When running via the clickable Run | Debug above the test on v3.50.0 i get No tests match regular expression "^const MyWidget\(\)( \(variant: .*\))?$".

  10. DanTup commented on Oct 3, 2022

    @DanTup
    Member

    @jtdLab that's expected right now, using line/col has not been implemented in the extension yet.

    You can use dart test foo_test.dart?line=1 from the terminal to verify where package:tests's support for line/cols works for this example. If it does, then once I update the extension to use this (implementing this issue), then it should also work from the Run/Debug CodeLens links.

  11. jtdLab commented on Oct 3, 2022

    @jtdLab

    @DanTup Perfect thank you a lot

  12. jtdLab commented on Oct 3, 2022

    @jtdLab

    @DanTup Let <LINE> be the line of the test. When running dart test foo_test.dart?line=<LINE> i get no matches found: foo_test.dart?line=<LINE> on test: ^1.21.6 so looks like this case is not covered there

  13. 6 remaining items

  14. modified the milestones: On Deck, v3.62.0 on Feb 27, 2023
  15. modified the milestones: v3.62.0, v3.64.0 on Mar 23, 2023
  16. DanTup commented on Apr 19, 2023

    @DanTup
    Member

    In the next release (and the pre-release version just pushed today - v3.63.20240419), you can choose to have tests executed using their line numbers rather than their names. This fixes a number of issues including this one, caused by not always being able to statically compute the exact name of a test.

    Test Invocation settings

    Please let me know if you find any issues with this functionality!

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