pan*_*ari 7 integration-testing flutter
我正在尝试使用在运行测试之前设置特定区域设置的integration_test包来进行测试。我尝试了以下方法(与 WidgetTests 中的方法很接近):
await tester.binding.setLocale('en', 'US');
app.main();
await tester.idle();
await tester.pumpAndSettle();
// The app is still using the default locale of the phone...
Run Code Online (Sandbox Code Playgroud)
这个需要在驱动里设置吗?这是我当前在驱动程序中的设置:
// Some adb commands for granting permissions...
print('Starting test.');
final FlutterDriver driver = await FlutterDriver.connect();
final String data = await driver.requestData(
null,
timeout: const Duration(minutes: 1),
);
await driver.close();
// Some more adb commands to revoke permissions.
Run Code Online (Sandbox Code Playgroud)
这似乎不起作用。
我在这里发现了这个问题,但它没有使用该integration_test包,因此完全有不同的设置。
我能够通过将目标小部件包装在Localizations小部件中来本地化我的集成测试。就像是:
class WidgetTestWrapper extends StatelessWidget {
const WidgetTestWrapper({
Key? key,
required this.locale,
required this.child,
}) : super(key: key);
final Widget child;
final Locale locale;
static const localizationsDelegates = <LocalizationsDelegate>[
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
];
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Material(
child: Localizations(
locale: locale,
delegates: localizationsDelegates,
child: child,
),
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
Locale然后我在调用中传递所需的测试runApp。
例如,对于西班牙语美国 (es-US):
runApp(WidgetTestWrapper(locale: const Locale('es', 'US'), child: widgetUnderTest));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1375 次 |
| 最近记录: |