Repository: flutter
Issue: Rerunning the same `flutter test` test on a target device causes a full rebuild every time
Labels: tool,perf: speed,P2,team-tool,triaged-tool

`flutter test` is taking almost the same amount of time on a second run as the first, when the app should already be built.  
On iOS this causes every test run to take an additional ~15 seconds.

`test` is subverting `flutter assemble` caching logic by passing in a new temp directory target `listener.dart` path every run, even when running the same test.  This causes the build system to create a new build directory from the hash of the inputs including `TargetFile`. 

https://github.com/flutter/flutter/blob/61a0add2865c51bfee33939c1820709d1115c77d/packages/flutter_tools/lib/src/build_system/build_system.dart#L351-L358

Every subsequent test run shows the `assemble` steps as needing a rerun due to `InvalidatedReasonKind.inputChanged` since each new build directory is missing the file store cache file from the last run:
```
            [  +31 ms] debug_unpack_ios: Starting due to {InvalidatedReasonKind.inputChanged: The following inputs have updated contents: /Users/m/Projects/flutter/packages/flutter_tools/lib/src/build_system/targets/ios.dart,/Users/magder/Projects/flutter/bin/internal/engine.version}
            [+1026 ms] Skipping target: gen_localizations
            [   +5 ms] gen_dart_plugin_registrant: Starting due to {InvalidatedReasonKind.inputChanged: The following inputs have updated contents: /Users/m/Projects/plugins/packages/google_maps_flutter/google_maps_flutter/example/.dart_tool/package_config_subset}
            [   +4 ms] debug_unpack_ios: Complete
...
            [   +6 ms] gen_dart_plugin_registrant: Complete
```

For example, in [`google_maps_flutter` example project](https://github.com/flutter/plugins/tree/main/packages/google_maps_flutter/google_maps_flutter/example) running the same command twice:
```
$ flutter --no-color test --machine --start-paused --plain-name testGetVisibleRegion  -v integration_test/google_maps_test.dart
```

calls identical `assemble` except for the different `-dTargetFile`s:

> --verbose assemble --no-version-check --output=/Users/m/Projects/plugins/packages/google_maps_flutter/google_maps_flutter/example/build/ios/Debug-iphonesimulator/ -dTargetPlatform=ios -dTargetFile=/var/folders/bx/pyplw7v92lj58gm3_lztz5sc00mfq2/T/**flutter_tools.5RYflD/flutter_test_listener.sO5mgy**/listener.dart -dBuildMode=debug -dIosArchs=x86_64 -dSdkRoot=/Users/m/Applications/Xcode-14_beta3.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.0.sdk -dSplitDebugInfo= -dTreeShakeIcons=false -dTrackWidgetCreation=true -dDartObfuscation=false -dEnableBitcode= --ExtraGenSnapshotOptions= --DartDefines=RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ==,SU5URUdSQVRJT05fVEVTVF9TSE9VTERfUkVQT1JUX1JFU1VMVFNfVE9fTkFUSVZFPWZhbHNl --ExtraFrontEndOptions= -dCodesignIdentity=- debug_ios_bundle_flutter_assets

> --verbose assemble --no-version-check --output=/Users/m/Projects/plugins/packages/google_maps_flutter/google_maps_flutter/example/build/ios/Debug-iphonesimulator/ -dTargetPlatform=ios -dTargetFile=/var/folders/bx/pyplw7v92lj58gm3_lztz5sc00mfq2/T/**flutter_tools.r0Vvcj/flutter_test_listener.uguobQ**/listener.dart -dBuildMode=debug -dIosArchs=x86_64 -dSdkRoot=/Users/m/Applications/Xcode-14_beta3.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.0.sdk -dSplitDebugInfo= -dTreeShakeIcons=false -dTrackWidgetCreation=true -dDartObfuscation=false -dEnableBitcode= --ExtraGenSnapshotOptions= --DartDefines=RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ==,SU5URUdSQVRJT05fVEVTVF9TSE9VTERfUkVQT1JUX1JFU1VMVFNfVE9fTkFUSVZFPWZhbHNl --ExtraFrontEndOptions= -dCodesignIdentity=- debug_ios_bundle_flutter_assets

https://github.com/flutter/flutter/blob/db829c1e200823cd655a6e0ca326967ff89d9c4f/packages/flutter_tools/lib/src/test/flutter_platform.dart#L570-L578