Reland "Fail tests on exceptions raised after test completed (#144706)" (#144980)

Reverts flutter/flutter#144970

No changes in this PR compared to the original. The test failure was fixed by adding missing awaits in https://github.com/flutter/flutter/pull/144978.

Fixes https://github.com/flutter/flutter/issues/144353.
This commit is contained in:
Michael Goderbauer
2024-03-12 11:17:10 -07:00
committed by GitHub
parent 394269f9ea
commit 77651bc496
4 changed files with 54 additions and 7 deletions

View File

@@ -910,15 +910,14 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
// Ideally, once the test has failed we would stop getting errors from the test.
// However, if someone tries hard enough they could get in a state where this happens.
// If we silently dropped these errors on the ground, nobody would ever know. So instead
// we report them to the console. They don't cause test failures, but hopefully someone
// will see them in the logs at some point.
// we raise them and fail the test after it has already completed.
debugPrint = debugPrintOverride; // just in case the test overrides it -- otherwise we won't see the error!
FlutterError.dumpErrorToConsole(FlutterErrorDetails(
reportTestException(FlutterErrorDetails(
exception: exception,
stack: stack,
context: ErrorDescription('running a test (but after the test had completed)'),
library: 'Flutter test framework',
), forceReport: true);
), description);
return;
}
// This is where test failures, e.g. those in expect(), will end up.