我正在为 Flutter Web 应用程序开发 Flutter integration_tests。当我启动我的 main() 应用程序时,系统会抛出异常“ImageCodecException:无法解码图像数据”。在上述情况下,考虑到我期望出现异常,如果抛出异常,我希望测试通过。我如何断言ImageCodeException
?
试过:
testWidgets('Test for invalid file upload', (WidgetTester tester) async {
app.main();
FlutterError.onError = (FlutterErrorDetails data) {
if (data.exception is FlutterError) {
final fErr = data.exception as FlutterError;
if (fErr.message == 'Failed to decode image data.') {
return;
}
}
FlutterError.presentError(data);
};
});
例外:
══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞═════════════════
The following ImageCodecException was thrown resolving an image
codec:
Failed to decode image data.
Image source: encoded image bytes
我已经覆盖了FlutterError.onError
确实绕过了异常..我如何断言特定ImageCodecException
异常?