我有一个用于我名为DefaultDrawer
的抽屉的小部件测试。我还想测试我在DefaultDrawerState.
内制作的方法,例如,
class DefaultDrawerState extends State<DefaultDrawer> {
@override
Widget build(BuildContext context) {
// ..build..
}
Widget _circleAvatar() {
// a method I want to test
}
}
当_circleAvatar()
查找者似乎无法在我的小部件或其状态内调用方法时,如何测试方法flutter_test
?
下面是我现在的测试文件,没有测试小部件中的方法:
void main() {
testWidgets('Drawer Test', (WidgetTester tester) async {
final key = GlobalKey<ScaffoldState>();
await tester.pumpWidget(
MaterialApp(home: Scaffold(key: key, drawer: DefaultDrawer())));
// open drawer
key.currentState.openDrawer();
await tester.pump();
// did drawer open?
final drawerFinder = find.byType(Drawer);
expect(drawerFinder, findsOneWidget);
});
}