[英]Flutter. How to test that there is no overflows with integration tests?
我使用flutter_driver在Flutter中進行集成測試。 在某些屏幕上,按鈕上的文字會出現溢出錯誤 我想創建一個可以顯示溢出發生的測試。 因此,當我在一堆虛擬/真實設備上運行所有集成測試時,我可以看到UI未正確定位。
沒有必要進行集成測試。 小部件測試會做。
由於Widget測試在啟用斷言的情況下運行,因此使用將溢出的窗口小部件調用tester.pumpWidget
將引發異常,從而進行失敗的測試。
例如,以下測試將失敗:
testWidgets('overflow', (tester) async {
await tester.pumpWidget(Row(
textDirection: TextDirection.ltr,
children: <Widget>[
// too big to fit in the default size of the row
Container(width: 99999),
],
));
});
請注意,可以自定義窗口小部件測試的屏幕大小。 請參閱如何在不同的屏幕尺寸上測試Flutter小部件?
或者,我們可以將測試的小部件包裝到Container
如下所示:
await tester.pumpWidget(Container(
alignment: Alignment.center,
width: <my screen widget>,
height: <my screen height>,
child: <the widget which I want to test overflow on>,
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.