【发布时间】:2020-05-13 07:32:24
【问题描述】:
有没有人建议如何在单元测试中找到我的小部件树中的以下单选按钮?
来自debugDumpApp() 我要查找的小部件位于此 sn-p 的底部:
│ ├InkWell(gestures: [tap], clipped to BoxShape.rectangle, state: _InkResponseState<InkResponse>#e573c)
│ │└Actions(dispatcher: null, actions: {[<SelectAction>]: Closure: () => Action from Function '_createAction@613059085':., [<ActivateAction>]: Closure: () => Action from Function '_createAction@613059085':.})
│ │ └Focus(dependencies: [_FocusMarker], state: _FocusState#e7131)
│ │ └_FocusMarker
│ │ └Semantics(container: false, properties: SemanticsProperties, label: null, value: null, hint: null, hintOverrides: null, renderObject: RenderSemanticsAnnotations#e56d2 relayoutBoundary=up3)
│ │ └MouseRegion(listeners: [enter, exit], renderObject: RenderMouseRegion#61069 relayoutBoundary=up4)
│ │ └GestureDetector(startBehavior: start)
│ │ └RawGestureDetector(state: RawGestureDetectorState#51044(gestures: [tap], behavior: opaque))
│ │ └_GestureSemantics(renderObject: RenderSemanticsGestureHandler#8ee96 relayoutBoundary=up5)
│ │ └Listener
│ │ └_PointerListener(listeners: [down], behavior: opaque, renderObject: RenderPointerListener#125af relayoutBoundary=up6)
│ │ └Row(direction: horizontal, mainAxisAlignment: start, crossAxisAlignment: center, dependencies: [Directionality], renderObject: RenderFlex#2d677 relayoutBoundary=up7)
│ │ ├Radio<String>(dependencies: [_LocalizationsScope-[GlobalKey#eab41], _InheritedTheme], state: _RadioState<String>#e39e8(tickers: tracking 4 tickers))
找不到的单元测试:
final widget = MaterialApp(
home: Scaffold(
body: RadioListWidget(
radioList: radiolist,
onChange: (value) {
selected = value;
},
),
),
);
testWidgets('it behaves the same as tapping the text', (tester) async {
await tester.pumpWidget(widget);
debugDumpApp();
await tester.tap(find.byType(Radio).first);
expect(selected, 'radio 1');
});
【问题讨论】:
标签: flutter flutter-test