Skip to content

flutter run test/widget_test.dart no longer works #24650

Closed

Description

@jamesderlin

(I discussed this with @jonahwilliams already, but I'm filing this to make sure we're tracking it.)

flutter run test/widget_test.dart is broken after the recent test_api changes. Attempting it will hit various runtime exceptions such as:

NoSuchMethodError: The method 'test' was called on null.
NoSuchMethodError: The method 'setUp' was called on null.
NoSuchMethodError: The method 'tearDown' was called on null.

We document that people can use flutter run on their widget tests to help debug widget tests, so this should be expected to work.

Activity

  1. added
    a: tests"flutter test", flutter_test, or one of our tests
    on Nov 22, 2018
  2. jonahwilliams commented on Nov 23, 2018

    @jonahwilliams
    Contributor

    I'll put together documentation on how to make this work. In general:

    import 'package:flutter_test/flutter_test.dart' hide group;
    import 'package:test/test.dart' show group;
    
    void main() {
      group('..', () {
        /// Tests
      });
    }
  3. zoechi commented on Nov 26, 2018

    @zoechi
    Contributor

    What is the reasoning behind that.
    Does group from flutter_test not work when run on a device with flutter run?

  4. added this to the milestone on Nov 26, 2018
  5. jonahwilliams commented on Nov 26, 2018

    @jonahwilliams
    Contributor

    Correct. The difference is the group method exposed by package test includes fallback logic to allow self-invoking tests. This also includes a larger set of dependencies, and isn't useful for "regular" flutter tests.

    Highly technical explanation:

    group(...) {
      if (someEnvNotSetup) {
        setUpEnv();
      }
      real.group(...);
    }

    We could get around this by running the flutter run testfile through a test entry-point like we do for normal flutter tests. This might require an additional flag or separate command, or it might not if setting up the test env has no side effects for a normal debug mode flutter run

  6. zoechi commented on Nov 26, 2018

    @zoechi
    Contributor

    I think it's worth investigating to find a way so that imports don't need to be changed between flutter run and flutter test runs.

  7. jonahwilliams commented on Nov 26, 2018

    @jonahwilliams
    Contributor

    agreed. I think the problem isn't so much the imports, but that the solution is completely unintuitive.

  8. Hixie commented on Nov 28, 2018

    @Hixie
    Contributor

    Why can't we just run the callbacks directly? I don't understand what needs to be set up.

  9. Hixie commented on Nov 28, 2018

    @Hixie
    Contributor

    (I mean, in test_api, why can't group('', foo) just call foo(), at least if there's no test framework loaded.)

  10. jonahwilliams commented on Nov 28, 2018

    @jonahwilliams
    Contributor

    group/test and friends require a Declarer to set themselves up. This manages the current state of the tests and handles communication with the command line/tracks outstanding callbacks and such

    I think the solution is for flutter_test to provide the same capability as package:test, namely to handle setting up the Declarer when there isn't one in the current zone.

  11. self-assigned this
    on Dec 1, 2018
  12. jonahwilliams commented on Dec 2, 2018

    @jonahwilliams
    Contributor

    Update: I've found that it is possible to restore the ability to run tests directly without increasing dependency count or modifying the entrypoints. Working this into a small PR in the next few days

  13. github-actions commented on Aug 14, 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.

  14. locked as resolved and limited conversation to collaborators on Aug 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

a: tests"flutter test", flutter_test, or one of our testsc: regressionIt was better in the past than it is nowcustomer: productd: api docsIssues with https://api.flutter.dev/

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions