【发布时间】:2021-03-19 15:21:48
【问题描述】:
我需要编写一个颤振小部件测试来测试使用 GoogleFonts 插件的小部件。但是,它给出了正确的网络故障,因为测试套装无法访问互联网。问题是 GoogleFonts.majorMonoDisplayTextTheme 是一个静态方法,在小部件测试中使用时无法模拟 GoogleFont 类。
Error: google_fonts was unable to load font MajorMonoDisplay-Regular because the following exception occurred:
Exception: Failed to load font with URL: https://fonts.gstatic.com/s/a/9901077f5681d4ec7e01e0ebe4bd61ba47669c64a7aedea472cd94fe1175751b.ttf
小部件使用:
Container(
padding: EdgeInsets.only(top: 10),
child: Text(
_now,
style: GoogleFonts.majorMonoDisplayTextTheme(Theme.of(context).textTheme).headline3,
),
),
小部件测试方法:
testWidgets(
'Shoudl display _now text',
(WidgetTester tester) async {
await tester.pumpWidget(_TestWidgetWithGoogleFont);
await tester.pumpAndSettle();
expect(find.byType(Text), findsOneWidget);
});
【问题讨论】:
标签: flutter mobile flutter-test google-fonts