Repository: flutter
Issue: [integration_test] If tests fail, integration_response_data.json is not created 
Labels: a: tests,framework,f: integration_test,has reproducible steps,P2,team-framework,triaged-framework,found in release: 3.19,found in release: 3.22

<!-- 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

<!-- You must include full steps to reproduce so that we can reproduce the problem. -->

1. Add this test to example test in master branch of plugins repo:
```dart
testWidgets('failure 2', (WidgetTester tester) async {
    (tester.binding as IntegrationTestWidgetsFlutterBinding).reportData = {'1': 1};
    expect(1 + 1, 2);
  });
```
and integration_test.dart:
```dart
import 'package:integration_test/integration_test_driver.dart' as integration_test_driver;

Future<void> main() {
  integration_test_driver.testOutputsDirectory = 'integration_test/gherkin/reports';

  return integration_test_driver.integrationDriver();
}
```
2. Run tests
3. Change `expect(1 + 1, 2);` to `expect(1 + 1, 3);`
4. Delete integration_response_data.json
4. Run tests

**Expected results:** On step 2 i expect {"1": 1} json file. On step 4 i expect same file to be created again

**Actual results:** On step 2 everything is fine, on step 4 file is not created.

**Reason:** Because `responseDataCallback` is called only if `response.allTestsPassed` is true (which is not the case if tests fail)(https://github.com/flutter/plugins/blob/f3024731b090659edaa92d01416549c690f65678/packages/integration_test/lib/integration_test_driver.dart#L81). But even if we call that callback here and fix "file not created" problem, there is another one:
response.data will be null. Exact reason is unknown to me yet, but this callback is called earlier than tests or frameworks can write to `binding.reportData`. So, if i add `await responseDataCallback(response.data);` to `else` statement on L82, file generated will contain just `null` despite what we passed in tests. This blocks reporting ability of testing frameworks when tests fail, because they can't write files themselves and rely on integration_test_driver to do it.

<details>
  <summary>Logs</summary>

```
Using device iPhone 8 Plus.
Starting application: test_driver/failure.dart
Warning: Missing build name (CFBundleShortVersionString).
Warning: Missing build number (CFBundleVersion).
Action Required: You must set a build name and number in the pubspec.yaml file version field before submitting to the App Store.
Running Xcode build...                                                  
 └─Compiling, linking and signing...                         4.3s
Xcode build done.                                           16.9s
flutter: Observatory listening on http://127.0.0.1:57170/CD-CwTHQPAM=/
VMServiceFlutterDriver: Connecting to Flutter application at http://127.0.0.1:57170/CD-CwTHQPAM=/
VMServiceFlutterDriver: Isolate found with number: 2615774461649659
VMServiceFlutterDriver: Isolate is paused at start.
VMServiceFlutterDriver: Attempting to resume isolate
flutter: 00:00 +0: failure 2
VMServiceFlutterDriver: Connected to Flutter application.
flutter: (The following exception is now available via WidgetTester.takeException:)
flutter: ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
flutter: The following TestFailure object was thrown running a test:
flutter:   Expected: <3>
flutter:   Actual: <2>
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #4      main.<anonymous closure> (file:///Users/voronin/plugins/packages/integration_test/example/test_driver/failure.dart:26:5)
flutter: #5      testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:146:29)
flutter: <asynchronous suspension>
flutter: #6      testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart)
flutter: #7      TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:796:19)
flutter: <asynchronous suspension>
flutter: #10     TestWidgetsFlutterBinding._runTest (package:flutter_test/src/binding.dart:777:14)
flutter: #11     LiveTestWidgetsFlutterBinding.runTest (package:flutter_test/src/binding.dart:1605:12)
flutter: #12     IntegrationTestWidgetsFlutterBinding.runTest (package:integration_test/integration_test.dart:194:17)
flutter: #13     testWidgets.<anonymous closure> (package:flutter_test/src/widget_tester.dart:138:24)
flutter: #14     Declarer.test.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/declarer.dart:175:19)
flutter: <asynchronous suspension>
flutter: #15     Declarer.test.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/declarer.dart)
flutter: #20     Declarer.test.<anonymous closure> (package:test_api/src/backend/declarer.dart:173:13)
flutter: #21     Invoker.waitForOutstandingCallbacks.<anonymous closure> (package:test_api/src/backend/invoker.dart:231:15)
flutter: #26     Invoker.waitForOutstandingCallbacks (package:test_api/src/backend/invoker.dart:228:5)
flutter: #27     Invoker._onRun.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/invoker.dart:383:17)
flutter: <asynchronous suspension>
flutter: #28     Invoker._onRun.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/invoker.dart)
flutter: #33     Invoker._onRun.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/invoker.dart:370:9)
flutter: #34     Invoker._guardIfGuarded (package:test_api/src/backend/invoker.dart:415:15)
flutter: #35     Invoker._onRun.<anonymous closure> (package:test_api/src/backend/invoker.dart:369:7)
flutter: #42     Invoker._onRun (package:test_api/src/backend/invoker.dart:368:11)
flutter: #43     LiveTestController.run (package:test_api/src/backend/live_test_controller.dart:153:11)
flutter: (elided 31 frames from dart:async and package:stack_trace)
flutter:
flutter: This was caught by the test expectation on the following line:
flutter:   file:///Users/voronin/plugins/packages/integration_test/example/test_driver/failure.dart line 26
flutter: The test description was:
flutter:   failure 2
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
flutter: (If WidgetTester.takeException is called, the above exception will be ignored. If it is not, then the above exception will be dumped when another exception is caught by the framework or when the test ends, whichever happens
first, and then the test will fail due to having not caught or expected the exception.)
flutter: ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
flutter: The following TestFailure object was thrown running a test:
flutter:   Expected: <3>
flutter:   Actual: <2>
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #4      main.<anonymous closure> (file:///Users/voronin/plugins/packages/integration_test/example/test_driver/failure.dart:26:5)
flutter: #5      testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:146:29)
flutter: <asynchronous suspension>
flutter: #6      testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart)
flutter: #7      TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:796:19)
flutter: <asynchronous suspension>
flutter: #10     TestWidgetsFlutterBinding._runTest (package:flutter_test/src/binding.dart:777:14)
flutter: #11     LiveTestWidgetsFlutterBinding.runTest (package:flutter_test/src/binding.dart:1605:12)
flutter: #12     IntegrationTestWidgetsFlutterBinding.runTest (package:integration_test/integration_test.dart:194:17)
flutter: #13     testWidgets.<anonymous closure> (package:flutter_test/src/widget_tester.dart:138:24)
flutter: #14     Declarer.test.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/declarer.dart:175:19)
flutter: <asynchronous suspension>
flutter: #15     Declarer.test.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/declarer.dart)
flutter: #20     Declarer.test.<anonymous closure> (package:test_api/src/backend/declarer.dart:173:13)
flutter: #21     Invoker.waitForOutstandingCallbacks.<anonymous closure> (package:test_api/src/backend/invoker.dart:231:15)
flutter: #26     Invoker.waitForOutstandingCallbacks (package:test_api/src/backend/invoker.dart:228:5)
flutter: #27     Invoker._onRun.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/invoker.dart:383:17)
flutter: <asynchronous suspension>
flutter: #28     Invoker._onRun.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/invoker.dart)
flutter: #33     Invoker._onRun.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/invoker.dart:370:9)
flutter: #34     Invoker._guardIfGuarded (package:test_api/src/backend/invoker.dart:415:15)
flutter: #35     Invoker._onRun.<anonymous closure> (package:test_api/src/backend/invoker.dart:369:7)
flutter: #42     Invoker._onRun (package:test_api/src/backend/invoker.dart:368:11)
flutter: #43     LiveTestController.run (package:test_api/src/backend/live_test_controller.dart:153:11)
flutter: (elided 31 frames from dart:async and package:stack_trace)
flutter:
flutter: This was caught by the test expectation on the following line:
flutter:   file:///Users/voronin/plugins/packages/integration_test/example/test_driver/failure.dart line 26
flutter: The test description was:
flutter:   failure 2
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
flutter: 00:00 +0: failure 2 [E]
flutter:   Test failed. See exception logs above.
  The test description was: failure 2
flutter:
flutter: 00:00 +0 -1: (tearDownAll)
flutter: Warning: integration_test test plugin was not detected.
flutter: 00:00 +1 -1: Some tests failed.
Failure Details:
Failure in method: failure 2
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞═════════════════
The following TestFailure object was thrown running a test:
  Expected: <3>
  Actual: <2>

When the exception was thrown, this was the stack:
#4      main.<anonymous closure> (file:///Users/voronin/plugins/packages/integration_test/example/test_driver/failure.dart:26:5)
#5      testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:146:29)
<asynchronous suspension>
#6      testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart)
#7      TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:796:19)
<asynchronous suspension>
#10     TestWidgetsFlutterBinding._runTest (package:flutter_test/src/binding.dart:777:14)
#11     LiveTestWidgetsFlutterBinding.runTest (package:flutter_test/src/binding.dart:1605:12)
#12     IntegrationTestWidgetsFlutterBinding.runTest (package:integration_test/integration_test.dart:194:17)
#13     testWidgets.<anonymous closure> (package:flutter_test/src/widget_tester.dart:138:24)
#14     Declarer.test.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/declarer.dart:175:19)
<asynchronous suspension>
#15     Declarer.test.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/declarer.dart)
#20     Declarer.test.<anonymous closure> (package:test_api/src/backend/declarer.dart:173:13)
#21     Invoker.waitForOutstandingCallbacks.<anonymous closure> (package:test_api/src/backend/invoker.dart:231:15)
#26     Invoker.waitForOutstandingCallbacks (package:test_api/src/backend/invoker.dart:228:5)
#27     Invoker._onRun.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/invoker.dart:383:17)
<asynchronous suspension>
#28     Invoker._onRun.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/invoker.dart)
#33     Invoker._onRun.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/invoker.dart:370:9)
#34     Invoker._guardIfGuarded (package:test_api/src/backend/invoker.dart:415:15)
#35     Invoker._onRun.<anonymous closure> (package:test_api/src/backend/invoker.dart:369:7)
#42     Invoker._onRun (package:test_api/src/backend/invoker.dart:368:11)
#43     LiveTestController.run (package:test_api/src/backend/live_test_controller.dart:153:11)
(elided 31 frames from dart:async and package:stack_trace)

This was caught by the test expectation on the following line:
  file:///Users/voronin/plugins/packages/integration_test/example/test_driver/failure.dart line 26
The test description was:
  failure 2
═════════════════════════════════════════════════════════════════

end of failure 1



Stopping application instance.
Driver tests failed: 1

```

<!-- Finally, paste the output of running `flutter doctor -v` here. -->

```
[✓] Flutter (Channel stable, 1.22.5, on Mac OS X 10.15.7 19H2 darwin-x64, locale en-RU)
    • Flutter version 1.22.5 at /usr/local/flutter
    • Framework revision 7891006299 (6 weeks ago), 2020-12-10 11:54:40 -0800
    • Engine revision ae90085a84
    • Dart version 2.10.4

 
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at /Users/voronin/Library/Android/sdk
    • Platform android-30, build-tools 30.0.2
    • ANDROID_HOME = /Users/voronin/Library/Android/sdk
    • Java binary at: /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.9+11)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 12.1)
    • Xcode at /Applications/Xcode-12.1.app/Contents/Developer
    • Xcode 12.1, Build version 12A7403
    • CocoaPods version 1.10.0

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).

[✓] IntelliJ IDEA Ultimate Edition (version 2020.1)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin version 46.0.3
    • Dart plugin version 201.7223.43

[!] VS Code (version 1.52.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    ✗ Flutter extension not installed; install from
      https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (1 available)
    • iPhone 8 Plus (mobile) • AD6DDB6C-44AB-4655-81C4-AAC5C241F4A2 • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-7 (simulator)

! Doctor found issues in 2 categories.

```

</details>