Repository: flutter
Issue: [Proposal] Warn/error if `IntegrationTestWidgetsFlutterBinding` is constructed within a test `group`
Labels: a: tests,framework,d: api docs,c: proposal,f: integration_test,P2,team-framework,triaged-framework

<!-- Thank you for using Flutter!

     If you are looking for support, please check out our documentation
     or consider asking a question on Stack Overflow:
      * https://flutter.dev/
      * https://api.flutter.dev/
      * https://stackoverflow.com/questions/tagged/flutter?sort=frequent

     If you have found a bug or if our documentation doesn't have an answer
     to what you're looking for, then fill out the template below. Please read
     our guide to filing a bug first: https://flutter.dev/docs/resources/bug-reports
-->

## Bug description

I wrongly did the following. The code below seems clear, but indeed it was hidden in a ton of my other code, so it took some time before I finally realized it is this bug.

```dart
// some_test_file.dart
void main() {
  group('group one', () {
    var binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
    test('test one', () async { await Future.delayed(Duration(seconds: 10)); });
  });
  group('group two', () {
    test('test two', () async { await Future.delayed(Duration(seconds: 10)); });
  });
}
```

Then run it: `flutter drive`

What happened:

after "test one" is executed, while "test two" is executing, the test automagically halts :(

## Why the bug?

Look at source:

```dart
class IntegrationTestWidgetsFlutterBinding extends LiveTestWidgetsFlutterBinding implements IntegrationTestResults {
  IntegrationTestWidgetsFlutterBinding() {
    tearDownAll(() async {
...   
        await integrationTestChannel.invokeMethod<void>(
          'allTestsFinished',
...
}
```

In other words, once `tearDownAll` is called, it thinks "all tests have finished".

However, if `IntegrationTestWidgetsFlutterBinding.ensureInitialized()` is called *inside* a `group`, the `tearDownAll` will be fired *not* when *all* tests finish, but when *that group* of tests finish!

<!--
     Please tell us the problem you are running into that led to you wanting
     a new feature.

     Is your feature request related to a problem? Please give a clear and
     concise description of what the problem is.

     Describe the alternative solutions you've considered. Is there a package
     on pub.dev/flutter that already solves this?
-->

## Proposal

### Part 1: code

I can make a PR for it. Proposal is that, inside constructor, do something like:

```dart
class IntegrationTestWidgetsFlutterBinding extends LiveTestWidgetsFlutterBinding implements IntegrationTestResults {
  IntegrationTestWidgetsFlutterBinding() {
    check_that_this_method_is_not_called_within_any_test_groups_otherwise_throw_error(); // <--- THIS IS ADDED
    tearDownAll(() async {
...   
        await integrationTestChannel.invokeMethod<void>(
          'allTestsFinished',
...
}
```

### part 2: doc

https://docs.flutter.dev/cookbook/testing/integration/introduction only says:

> Initialize IntegrationTestWidgetsFlutterBinding, a singleton service that executes tests on a physical device.

But I did not realize (and I guess most people will not infer that) "this MUST be called OUTSIDE any group or you might end up with an unexpected behavior".

So, adding a few words to the doc will be helpful.

<!--
     Briefly but precisely describe what you would like Flutter to be able to do.

     Consider attaching something showing what you are imagining:
      * images
      * videos
      * code samples

     Does this have to be provided by Flutter directly, or can it be provided
     by a package on pub.dev/flutter? If so, maybe consider implementing and
     publishing such a package rather than filing a bug.
-->