首页 > 解决方案 > 如何调试颤振单元测试?

问题描述

我正在尝试点击 aFlatButton我在屏幕上有很多东西,但它们都有独特Key的 s。我有一个print作为函数中唯一的行onPressed

这是有效的,我在控制台中看到了打印行:

expect(find.byKey(Key('q1a2')), findsOneWidget);
await tester.tap(find.byKey(Key('q1a2')));
await tester.pumpAndSettle(Duration(milliseconds: 500));

这不起作用,我在控制台中看不到打印行:

expect(find.byKey(Key('q3a2')), findsOneWidget);
await tester.tap(find.byKey(Key('q3a2')));
await tester.pumpAndSettle(Duration(milliseconds: 500));

两个示例中的expect通行证。我该如何调试呢?

FlatButton部件代码:

FlatButton(
  key: Key('q${questionId}a$score'),
  color: isSelected ? Colors.amberAccent : Colors.transparent,
  highlightColor: Colors.transparent,
  splashColor: Colors.amberAccent.withOpacity(0.2),
  shape: CircleBorder(
    side: BorderSide(
      color: isSelected ? Colors.amberAccent : Colors.grey[300],
      width: 1.0
    )
  ),
  onPressed: () {
    print('WTF!');
  },
  child: Text(
    score.toString(),
    style: TextStyle(
      color: isSelected ? Colors.grey[900] : Colors.grey[600],
      fontSize: isSelected ? 20.0 : 18.0,
      fontWeight: isSelected ? FontWeight.normal : FontWeight.w300
    )
  )
),

标签: flutter

解决方案


推荐阅读