Is there a way to test for building a widget throwing an exception.
I tried this in testWidgets but it doesn't recognize the error.
expectLater(() async {
await tester.pumpWidget(...);
}, throwsException);
You can only catch exceptions thrown by code invoked by your code.
build() is invoked by the Flutter framework and therefore errors land there.
You can register a custom error handler for such exceptions in your test
final errorHandled = expectAsync0((){});
FlutterError.onError = (errorDetails) {
// handle error
errorHandled();
});
This way the test will fail if errorHandled isn't called before the test times out.
https://docs.flutter.io/flutter/foundation/FlutterError-class.html
build.