Repository: flutter
Issue: runZoned with zoneValues unavailable during integration_test
Labels: a: tests,framework,has reproducible steps,P2,found in release: 2.8,found in release: 2.9,found in release: 2.10,found in release: 3.0,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
-->

## Steps to Reproduce

1. Create a basic flutter app which wraps `runApp` with `runZoned` and provides a custom zone value:

```dart
import 'dart:async';

import 'package:flutter/material.dart';

const zoneKey = Object();

void main() {
  runZoned(
    () => runApp(const MyApp()),
    zoneValues: {zoneKey: 'Hello World'},
  );
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final zoneValue = Zone.current[zoneKey];
    print('MyApp.build() $zoneValue'); // NULL during integration_test run
    return const MaterialApp();
  }
}
```

2. Write an integration test:

```dart
import 'package:flutter_test/flutter_test.dart';
import 'package:example/main.dart' as app;

void main() {
  group('App', () {
    testWidgets('renders MyApp', (tester) async {
      app.main();
      await tester.pumpAndSettle();
      expect(find.byType(app.MyApp), findsOneWidget);
    });
  });
}
```

3. Run the integration test `flutter test integration_test`
4. Observe that the zone value is null within the `build` method of `MyApp`

**Expected results:** <!-- what did you want to see? -->

I'd expect the zone value to be available within the `build` method since `runApp` was executed within the zone.

**Actual results:** <!-- what did you see? -->

The zone value is `null` within the `build` method during the integration_test run.

### Additional Context

Even when the entire test suite is wrapped in `runZoned`, the zone values are not available during an integration_test run:

```dart
void main() {
  runZoned(() {
    final zoneValue = Zone.current[app.zoneKey];
    print('test.main(), $zoneValue'); // Hello Test
    group('App', () {
      final zoneValue = Zone.current[app.zoneKey];
      print('test.group(), $zoneValue'); // Hello Test
      testWidgets('renders MyApp', (tester) async {
        final zoneValue = Zone.current[app.zoneKey];
        print('test.testWidgets(), $zoneValue'); // null
        app.main();
        await tester.pumpAndSettle();
        expect(find.byType(app.MyApp), findsOneWidget);
      });
    });
  }, zoneValues: {app.zoneKey: 'Hello Test'});
}
```

It looks like `testWidgets` runs the body inside a new zone and does not fork the parent zone and inherit the `zoneValues`.

## Related Issues

- https://github.com/flutter/flutter/issues/94123
- https://github.com/flutter/flutter/issues/93676

<details>
  <summary>Logs</summary>

<!--
      Run your application with `flutter run --verbose` and attach all the
      log output below between the lines with the backticks. If there is an
      exception, please see if the error message includes enough information
      to explain how to solve the issue.
-->

```
{"CFBundleName":"zones","DTXcode":"1310","DTSDKName":"iphonesimulator15.0","UILaunchStoryboardName":"LaunchScreen","CFBundleIcons~ipad":{"CFBundlePrimaryIcon":{"CFBundleIconFiles":["AppIcon20x20","AppIcon29x29","AppIcon40x40","AppIcon60x60","AppIcon76x76","AppIcon83.5x83.
5"],"CFBundleIconName":"AppIcon"}},"DTSDKBuild":"19A339","CFBundleDevelopmentRegion":"en","CFBundleVersion":"1","BuildMachineOSBuild":"21A559","DTPlatformName":"iphonesimulator","CFBundlePackageType":"APPL","UIMainStoryboardFile":"Main","CFBundleSupportedPlatforms":["iPho
neSimulator"],"CFBundleShortVersionString":"1.0.0","CFBundleInfoDictionaryVersion":"6.0","CFBundleExecutable":"Runner","DTCompiler":"com.apple.compilers.llvm.clang.1_0","UISupportedInterfaceOrientations~ipad":["UIInterfaceOrientationPortrait","UIInterfaceOrientationPortra
itUpsideDown","UIInterfaceOrientationLandscapeLeft","UIInterfaceOrientationLandscapeRight"],"MinimumOSVersion":"9.0","CFBundleIdentifier":"com.example.zones","UIDeviceFamily":[1,2],"DTPlatformVersion":"15.0","CFBundleSignature":"????","CFBundleIcons":{"CFBundlePrimaryIcon
":{"CFBundleIconFiles":["AppIcon20x20","AppIcon29x29","AppIcon40x40","AppIcon60x60"],"CFBundleIconName":"AppIcon"}},"DTXcodeBuild":"13A1030d","LSRequiresIPhoneOS":true,"UISupportedInterfaceOrientations":["UIInterfaceOrientationPortrait","UIInterfaceOrientationLandscapeLef
t","UIInterfaceOrientationLandscapeRight"],"UIViewControllerBasedStatusBarAppearance":false,"NSBonjourServices":["_dartobservatory._tcp"],"DTPlatformBuild":"19A339","NSLocalNetworkUsageDescription":"Allow Flutter tools on your computer to connect and debug your
application. This prompt will not appear on release builds."}
[   +4 ms] executing: xcrun simctl launch FCB4BE3E-33DA-49FC-A861-F647555D56A9 com.example.zones --enable-dart-profiling --enable-checked-mode --verify-entry-points --observatory-port=0
[ +205 ms] com.example.zones: 51465
[   +1 ms] Waiting for observatory port to be available...
[ +416 ms] Observatory URL on device: http://127.0.0.1:55348/QIoVQ24XVz0=/
[   +9 ms] Caching compiled dill
[  +51 ms] Connecting to service protocol: http://127.0.0.1:55348/QIoVQ24XVz0=/
[ +167 ms] Launching a Dart Developer Service (DDS) instance at http://127.0.0.1:0, connecting to VM service at http://127.0.0.1:55348/QIoVQ24XVz0=/.
[  +95 ms] DDS is listening at http://127.0.0.1:55351/1RcuH9jFcOE=/.
[  +59 ms] Successfully connected to service protocol: http://127.0.0.1:55348/QIoVQ24XVz0=/
[  +26 ms] DevFS: Creating new filesystem on the device (null)
[  +17 ms] DevFS: Created new filesystem on the device (file:///Users/felix/Library/Developer/CoreSimulator/Devices/FCB4BE3E-33DA-49FC-A861-F647555D56A9/data/Containers/Data/Application/42BE9414-534D-477C-ADEB-EDC73F58B7FA/tmp/zonesEyB4Fm/zones/)
[   +2 ms] Updating assets
[  +63 ms] Syncing files to device iPhone 13...
[   +2 ms] <- reset
[        ] Compiling dart to kernel with 0 updated files
[   +3 ms] <- recompile package:zones/main.dart 7fd16ad6-36b9-4ac5-99dd-f42726cef603
[        ] <- 7fd16ad6-36b9-4ac5-99dd-f42726cef603
[  +64 ms] Updating files.
[        ] DevFS: Sync finished
[        ] Syncing files to device iPhone 13... (completed in 71ms)
[        ] Synced 0.0MB.
[   +1 ms] <- accept
[   +6 ms] Connected to _flutterView/0x7fb30a810c20.
[   +3 ms] Flutter run key commands.
[   +1 ms] r Hot reload. 🔥🔥🔥
[        ] R Hot restart.
[        ] h List all available interactive commands.
[        ] d Detach (terminate "flutter run" but leave application running).
[        ] c Clear the screen
[        ] q Quit (terminate the application on the device).
[        ] 💪 Running with sound null safety 💪
[        ] An Observatory debugger and profiler on iPhone 13 is available at: http://127.0.0.1:55351/1RcuH9jFcOE=/
[ +490 ms] The Flutter DevTools debugger and profiler on iPhone 13 is available at: http://127.0.0.1:9102?uri=http://127.0.0.1:55351/1RcuH9jFcOE=/
[+4486 ms] Skipping target: gen_localizations
[        ] Skipping target: gen_dart_plugin_registrant
[        ] Skipping target: _composite
[        ] complete
[        ] Performing hot reload...
[  +11 ms] Scanned through 528 files in 6ms
[        ] Syncing files to device iPhone 13...
[        ] Compiling dart to kernel with 0 updated files
[        ] <- recompile package:zones/main.dart 564d0ee5-dbd9-4020-bfeb-4217c387483f
[        ] <- 564d0ee5-dbd9-4020-bfeb-4217c387483f
[   +6 ms] Updating files.
[   +2 ms] DevFS: Sync finished
[        ] Syncing files to device iPhone 13... (completed in 9ms)
[        ] Synced 0.0MB.
[  +11 ms] Reassembling application
[  +39 ms] Hot reload performed in 67ms.
[   +1 ms] Performing hot reload... (completed in 73ms)
[        ] Reloaded 0 libraries in 78ms.
```

<!--
     Run `flutter analyze` and attach any output of that command below.
     If there are any analysis errors, try resolving them before filing this issue.
-->

```
No issues found! (ran in 1.9s)
```

<!-- Finally, paste the output of running `flutter doctor -v` here. -->

```
[✓] Flutter (Channel beta, 2.7.0-3.1.pre, on macOS 12.0.1 21A559 darwin-x64, locale en-US)
    • Flutter version 2.7.0-3.1.pre at /Users/felix/fvm/versions/beta
    • Upstream repository git@github.com:flutter/flutter.git
    • Framework revision fc7015e35a (3 weeks ago), 2021-10-27 15:18:41 -0700
    • Engine revision a75e3b80f9
    • Dart version 2.15.0 (build 2.15.0-178.1.beta)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /Users/felix/Library/Android/sdk
    • Platform android-30, build-tools 29.0.2
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.1)
    • 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 1.8.0_242-release-1644-b3-6222593)

[✓] IntelliJ IDEA Community Edition (version 2021.2)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • 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

[✓] VS Code (version 1.60.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.27.0

[✓] VS Code (version 1.63.0-insider)
    • VS Code at /Applications/Visual Studio Code - Insiders.app/Contents
    • Flutter extension version 3.28.0

[✓] Connected device (3 available)
    • iPhone 13 (mobile) • FCB4BE3E-33DA-49FC-A861-F647555D56A9 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-15-0 (simulator)
    • macOS (desktop)    • macos                                • darwin-x64     • macOS 12.0.1 21A559 darwin-x64
    • Chrome (web)       • chrome                               • web-javascript • Google Chrome 95.0.4638.69

• No issues found!
```

</details>


<!--
      Consider also attaching screenshots and/or videos to better
      illustrate the issue.

      You can upload them directly on GitHub.
      Beware that video file size is limited to 10MB.
-->