[integration_test] Fix early reporting of results (#83685)
This commit is contained in:
@@ -294,5 +294,8 @@ abstract class IntegrationTestResults {
|
||||
Map<String, dynamic>? get reportData;
|
||||
|
||||
/// Whether all the test methods completed successfully.
|
||||
///
|
||||
/// Completes when the tests have finished. The boolean value will be true if
|
||||
/// all tests have passed, and false otherwise.
|
||||
Completer<bool> get allTestsPassed;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ class IntegrationTestWidgetsFlutterBinding extends LiveTestWidgetsFlutterBinding
|
||||
IntegrationTestWidgetsFlutterBinding() {
|
||||
tearDownAll(() async {
|
||||
if (!_allTestsPassed.isCompleted) {
|
||||
_allTestsPassed.complete(true);
|
||||
_allTestsPassed.complete(failureMethodsDetails.isEmpty);
|
||||
}
|
||||
callbackManager.cleanup();
|
||||
|
||||
@@ -83,9 +83,6 @@ https://flutter.dev/docs/testing/integration-tests#testing-on-firebase-test-lab
|
||||
reportTestException =
|
||||
(FlutterErrorDetails details, String testDescription) {
|
||||
results[testDescription] = Failure(testDescription, details.toString());
|
||||
if (!_allTestsPassed.isCompleted) {
|
||||
_allTestsPassed.complete(false);
|
||||
}
|
||||
oldTestExceptionReporter(details, testDescription);
|
||||
};
|
||||
}
|
||||
@@ -133,7 +130,7 @@ https://flutter.dev/docs/testing/integration-tests#testing-on-firebase-test-lab
|
||||
final Completer<bool> _allTestsPassed = Completer<bool>();
|
||||
|
||||
@override
|
||||
List<Failure> get failureMethodsDetails => _failures;
|
||||
List<Failure> get failureMethodsDetails => results.values.whereType<Failure>().toList();
|
||||
|
||||
/// Similar to [WidgetsFlutterBinding.ensureInitialized].
|
||||
///
|
||||
@@ -157,8 +154,6 @@ https://flutter.dev/docs/testing/integration-tests#testing-on-firebase-test-lab
|
||||
@visibleForTesting
|
||||
Map<String, Object> results = <String, Object>{};
|
||||
|
||||
List<Failure> get _failures => results.values.whereType<Failure>().toList();
|
||||
|
||||
/// The extra data for the reported result.
|
||||
///
|
||||
/// The values in `reportData` must be json-serializable objects or `null`.
|
||||
|
||||
@@ -42,6 +42,14 @@ Future<void> main() async {
|
||||
expect(results, containsPair('passing test', equals('success')));
|
||||
expect(results, containsPair('failing test', contains(_failureExcerpt)));
|
||||
});
|
||||
|
||||
test('when one test fails, then another passes', () async {
|
||||
final Map<String, dynamic>? results = await _runTest(path.join('test', 'data', 'fail_then_pass_test_script.dart'));
|
||||
|
||||
expect(results, hasLength(2));
|
||||
expect(results, containsPair('failing test', contains(_failureExcerpt)));
|
||||
expect(results, containsPair('passing test', equals('success')));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,9 @@ import 'package:integration_test/integration_test.dart';
|
||||
|
||||
Future<void> main() async {
|
||||
final IntegrationTestWidgetsFlutterBinding binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized() as IntegrationTestWidgetsFlutterBinding;
|
||||
binding.allTestsPassed.future.then((_) {
|
||||
print('IntegrationTestWidgetsFlutterBinding test results: ${jsonEncode(binding.results)}');
|
||||
});
|
||||
|
||||
testWidgets('failing test 1', (WidgetTester tester) async {
|
||||
expect(true, false);
|
||||
@@ -17,8 +20,4 @@ Future<void> main() async {
|
||||
testWidgets('failing test 2', (WidgetTester tester) async {
|
||||
expect(true, false);
|
||||
});
|
||||
|
||||
tearDownAll(() {
|
||||
print('IntegrationTestWidgetsFlutterBinding test results: ${jsonEncode(binding.results)}');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:integration_test/integration_test.dart';
|
||||
|
||||
Future<void> main() async {
|
||||
final IntegrationTestWidgetsFlutterBinding binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized() as IntegrationTestWidgetsFlutterBinding;
|
||||
binding.allTestsPassed.future.then((_) {
|
||||
print('IntegrationTestWidgetsFlutterBinding test results: ${jsonEncode(binding.results)}');
|
||||
});
|
||||
|
||||
testWidgets('failing test', (WidgetTester tester) async {
|
||||
expect(true, false);
|
||||
});
|
||||
|
||||
testWidgets('passing test', (WidgetTester tester) async {
|
||||
expect(true, true);
|
||||
});
|
||||
}
|
||||
@@ -9,6 +9,9 @@ import 'package:integration_test/integration_test.dart';
|
||||
|
||||
Future<void> main() async {
|
||||
final IntegrationTestWidgetsFlutterBinding binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized() as IntegrationTestWidgetsFlutterBinding;
|
||||
binding.allTestsPassed.future.then((_) {
|
||||
print('IntegrationTestWidgetsFlutterBinding test results: ${jsonEncode(binding.results)}');
|
||||
});
|
||||
|
||||
testWidgets('passing test 1', (WidgetTester tester) async {
|
||||
expect(true, true);
|
||||
@@ -17,9 +20,4 @@ Future<void> main() async {
|
||||
testWidgets('passing test 2', (WidgetTester tester) async {
|
||||
expect(true, true);
|
||||
});
|
||||
|
||||
tearDownAll(() {
|
||||
print(
|
||||
'IntegrationTestWidgetsFlutterBinding test results: ${jsonEncode(binding.results)}');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -9,6 +9,9 @@ import 'package:integration_test/integration_test.dart';
|
||||
|
||||
Future<void> main() async {
|
||||
final IntegrationTestWidgetsFlutterBinding binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized() as IntegrationTestWidgetsFlutterBinding;
|
||||
binding.allTestsPassed.future.then((_) {
|
||||
print('IntegrationTestWidgetsFlutterBinding test results: ${jsonEncode(binding.results)}');
|
||||
});
|
||||
|
||||
testWidgets('passing test', (WidgetTester tester) async {
|
||||
expect(true, true);
|
||||
@@ -17,9 +20,4 @@ Future<void> main() async {
|
||||
testWidgets('failing test', (WidgetTester tester) async {
|
||||
expect(true, false);
|
||||
});
|
||||
|
||||
tearDownAll(() {
|
||||
print(
|
||||
'IntegrationTestWidgetsFlutterBinding test results: ${jsonEncode(binding.results)}');
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user