Repository: flutter
Issue: Mocking all HTTP requests with 400 responses in tests without an option to disable it discourages the use of the helpful VCR approach in client/repository/request tests
Labels: a: tests,framework,c: proposal,P3,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
-->

### Use case

<!--
     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?
-->

There is [VCR](https://github.com/vcr/vcr) library in the Ruby World that allows to record real HTTP interactions (cassettes) first time a spec is run and use it as a mock response (with Webmock, for example) in the following spec runs.

There's also a Dart port of this approach: [github](https://github.com/alex-min/vcr) · [pub.dev](https://pub.dev/packages/vcr2). It stores requests in JSON format.

Worked liked a charm before all real requests in tests started to respond with mocked 400.

Now, this VCR approach generally encourages the same thing as the 400 mock — not to use real HTTP requests in tests. But makes it really easy to maintain API schema updates in the cassettes (stored responses) automatically without any manual copy-pasting (which is the only option now).

And by the way this is not only about widget tests (in which I wouldn't support real world HTTP requests myself) but I'm having this issue in unit/makeshift-request tests:

```dart
void main() {
  setUpAll(() {
    HttpOverrides.global = null;
  });

  group('ThingsClient', () {
    late VcrAdapter vcr;
    late HttpClient httpClient;
    late ThingsClient thingsClient;

    setUp(() {
      vcr = VcrAdapter();

      httpClient = HttpClient()
        ..httpClientAdapter = vcr;

      thingsClient = ThingsClient(httpClient: httpClient);
    });

    group('#fetchThings', () {
      setUp(() {
        vcr.useCassette('things_client/fetch_ things');
      });

      test('returns a list of things if the http call completes successfully', () async {
        expect(await thingsClient.fetchThings(), isA<List<Thing>>());
      });
    });
  });
 });
```

gives me:

```
Warning: At least one test in this suite creates an HttpClient. When running a test suite that uses TestWidgetsFlutterBinding, all HTTP requests will return status code 400, and no network request will actually be made. Any test expecting a real network connection and status code will fail.
```

### Proposal

Make mocking HTTP requests in Flutter tests optional/disableable/toggleable to allow developers to record HTTP interactions for their test mocks.

### Related discussions

https://github.com/flutter/flutter/issues/35318
https://github.com/flutter/flutter/issues/69574