Skip to content

When using variant parameter of testWidgets: No tests match regular expression.... when running individual tests #86659

Closed

Description

@martin-robert-fink

Steps to Reproduce

  1. Build start flutter default app: flutter create variant_test
  2. In the test folder, open widget_test.dart
  3. Add the following parameter to existing testWidgets('Counter increment smoke test'..., variant: TargetPlatformVariant.desktop());
  4. Attempt to run individual test and you'll get the error: No tests match regular expression...

There are NO other changes to the default code generated by flutter create, and only that one parameter to testWidgets causes the issue. Tests run if run from main, but not individual tests.

This is similar to dart issues: #1458 and #1492

Expected results:

Ability to run individual tests with no errors

Actual results:

No tests match regular expression....

Flutter doctor output:

flutter doctor -v
mfink@Martins-MBP-M1 variant_test % flutter doctor -v
[✓] Flutter (Channel dev, 2.4.0-4.0.pre, on macOS 11.4 20F71 darwin-arm, locale en-US)
    • Flutter version 2.4.0-4.0.pre at /Users/mfink/Developer/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision cc00e7e6bc (8 days ago), 2021-07-11 18:21:02 -0400
    • Engine revision ed25e8f01e
    • Dart version 2.14.0 (build 2.14.0-301.0.dev)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at /Users/mfink/Library/Android/sdk
    • Platform android-S, build-tools 30.0.2
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.5.1, Build version 12E507
    • CocoaPods version 1.10.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)

[✓] VS Code (version 1.58.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.24.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 11.4 20F71 darwin-arm
    • Chrome (web)    • chrome • web-javascript • Google Chrome 91.0.4472.114

• No issues found!

Activity

  1. DanTup commented on Jul 19, 2021

    @DanTup
    Contributor

    This happens because in VS Code when we run a single test, we put its name in the command line like this:

    flutter test --machine --name "^Counter increments smoke test$" test/widget_test.dart
    

    The --name argument is an exact match for the name of the test so that it doesn't match extra tests, for example if you had:

    test('Counter increments', () {});
    
    test('Counter increments when foo', () {});

    Without the $ on the end of the name, trying to run the first test would actually run both.

    When using variant, the name of the test is suffixed (in this case "Counter increments smoke test (TargetPlatform.windows)") and therefore no longer matches the pattern. The VS Code extension doesn't have enough information in the Outline data to know the variant exists, so it's hard to amend the expression.

    @jonahwilliams any thoughts on this? Is there a way that --name could take variation into account? Or could we perhaps make the name slightly more specific so my regex could account for it without being too greedy (for example "Counter increments smoke test (variant: TargetPlatform.windows)")?

  2. jonahwilliams commented on Jul 19, 2021

    @jonahwilliams
    Contributor

    I believe @gspencergoog added the variant feature, I would follow up with him

  3. gspencergoog commented on Jul 19, 2021

    @gspencergoog
    Contributor

    We could make the output include "variant:", sure.

    I would point out that the IntelliJ plugin just executes all tests that contain the given test name, so there is a difference in functionality between the two plugins. I'm not commenting on which way is better, just that there's a difference (they both seem to have their merits to me).

    It is sometimes useful to run only a particular variant, so you wouldn't want to make the regex too restrictive: I should be able to enter 'Counter increments (variant: TargetPlatform.windows)' and run just the Windows variant of the test.

  4. DanTup commented on Jul 19, 2021

    @DanTup
    Contributor

    I would point out that the IntelliJ plugin just executes all tests that contain the given test name, so there is a difference in functionality between the two plugins. I'm not commenting on which way is better, just that there's a difference (they both seem to have their merits to me).

    It might make sense to align them. That's what VS Code used to do, but it felt like a bug that if the user clicked "Run" next to one, we might run other tests too. @stevemessick do you think it makes sense to update IntelliJ? I'm not familiar with the UI for IntelliJ so I don't know if it makes more sense there than in VS Code. In VS Code we're invoking i from these Run/Debug links above the testWidgets call:

    Screenshot 2021-07-19 at 18 04 40

    That we're using the name of the test behind the scenes seems like a detail the user is hidden from, so running multiple looks strange.

    I should be able to enter 'Counter increments (variant: TargetPlatform.windows)' and run just the Windows variant of the test

    If we added a variant: prefix that would all still work in the cli. For VS Code there isn't anywhere you could choose to run one specific variant though, so clicking the Run/Debug links shown above would have to run all variants (described by the variant` argument).

    So if we can add a variant: prefix in the test name, my plan would be to add ( \(variant: .*\))? to the end of the regex to match tests with exactly this name, but optionally with that variant suffix:

    flutter test --name "^Counter increments smoke test( \(variant: .*\))?$" test/widget_test.dart
    

    Does this sound reasonable? I can file a PR to add the text and ensure it doesn't break anything.

  5. gspencergoog commented on Jul 19, 2021

    @gspencergoog
    Contributor

    Sounds reasonable to me.

  6. stevemessick commented on Jul 19, 2021

    @stevemessick
    Member
  7. added
    in triagePresently being triaged by the triage team
    a: tests"flutter test", flutter_test, or one of our tests
    d: intellijDevTools related - IntelliJ/flutter issues (most should be tracked in flutter/flutter-intellij)
    frameworkflutter/packages/flutter repository. See also f: labels.
    and removed
    in triagePresently being triaged by the triage team
    d: intellijDevTools related - IntelliJ/flutter issues (most should be tracked in flutter/flutter-intellij)
    on Jul 20, 2021
  8. DanTup commented on Jul 20, 2021

    @DanTup
    Contributor

    #86701 has landed in Flutter and Dart-Code/Dart-Code#3482 in the VS Code extension. The combination of these resolves this issue for VS Code (you'll need releases of both for this to start working). IntelliJ doesn't have this issue since its regex is less strict (though flutter/flutter-intellij#5650 will make this more aligned with VS Code's behaviour).

  9. github-actions commented on Aug 3, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  10. locked as resolved and limited conversation to collaborators on Aug 3, 2021
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

    a: tests"flutter test", flutter_test, or one of our testsframeworkflutter/packages/flutter repository. See also f: labels.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions