Unit testing 无法访问小部件测试中的颤振UI元素

Unit testing 无法访问小部件测试中的颤振UI元素,unit-testing,flutter,widget,bloc,Unit Testing,Flutter,Widget,Bloc,我正试图为我用bloc构建的颤振屏幕编写一个小部件测试。但是我无法通过测试访问我的任何小部件。以下是我的小部件测试代码: FeedbackListBloc feedbackListBloc; FeedbackListRepository feedbackListRepository; PrefStore prefStore; group('login error handling', () { feedbackListRepository = MockFeedbac

我正试图为我用bloc构建的颤振屏幕编写一个小部件测试。但是我无法通过测试访问我的任何小部件。以下是我的小部件测试代码:

    FeedbackListBloc feedbackListBloc;
  FeedbackListRepository feedbackListRepository;
  PrefStore prefStore;

  group('login error handling', () {
    feedbackListRepository = MockFeedbackListRepository();
    prefStore = MockPrefStore();
    feedbackListBloc = FeedbackListBloc(feedbackListRepository,prefStore);

    testWidgets('validate Feedback List widget', (WidgetTester tester) async {
      Widget testWidget = new MediaQuery(
          data: MediaQueryData(),
          child: MaterialApp(home: FeedbackList(feedbackListBloc: feedbackListBloc))
      );
      Widget localizedWidget = Localizations(
        delegates: [
          AppLocalizations.delegate,
          // Built-in localization of basic text for Material widgets
          GlobalMaterialLocalizations.delegate,
          // Built-in localization for text direction LTR/RTL
          GlobalWidgetsLocalizations.delegate,
        ],
        locale: Locale('en'),
        child: testWidget,
      );
      await tester.pumpWidget(localizedWidget);
      await tester.pumpAndSettle();
      expect(find.byIcon(Icons.add), findsOneWidget);
    });
  });
我的expect方法中总是出现以下错误:

test/widget_test/dashboard/feedback/feedback_list/ui/feedback_list_test.dart
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following TestFailure object was thrown running a test:
  Expected: exactly one matching node in the widget tree
  Actual: _WidgetTypeFinder:<zero widgets with type "CircularProgressIndicator" (ignoring offstage
widgets)>
   Which: means none were found but one was expected

When the exception was thrown, this was the stack:
#4      main.<anonymous closure>.<anonymous closure> (file:///Users/pankajsahdevea/Desktop/HD/Work/Haufe/Code/IF2.0/if_ui_Sep13,2019/test/widget_test/dashboard/feedback/feedback_list/ui/feedback_list_test.dart:45:7)
<asynchronous suspension>
#5      testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:124:25)
#6      TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:696:19)
<asynchronous suspension>
#9      TestWidgetsFlutterBinding._runTest (package:flutter_test/src/binding.dart:679:14)
#10     AutomatedTestWidgetsFlutterBinding.runTest.<anonymous closure> (package:flutter_test/src/binding.dart:1050:24)
#16     AutomatedTestWidgetsFlutterBinding.runTest (package:flutter_test/src/binding.dart:1047:15)
#17     testWidgets.<anonymous closure> (package:flutter_test/src/widget_tester.dart:121:22)
#18     Declarer.test.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/declarer.dart:171:27)
<asynchronous suspension>
#19     Invoker.waitForOutstandingCallbacks.<anonymous closure> (package:test_api/src/backend/invoker.dart:242:15)
#24     Invoker.waitForOutstandingCallbacks (package:test_api/src/backend/invoker.dart:239:5)
#25     Declarer.test.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/declarer.dart:169:33)
#30     Declarer.test.<anonymous closure> (package:test_api/src/backend/declarer.dart:168:13)
#31     Invoker._onRun.<anonymous closure>.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/invoker.dart:392:25)
#45     _Timer._runTimers (dart:isolate-patch/timer_impl.dart:384:19)
#46     _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:418:5)
#47     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:174:12)
(elided 28 frames from class _FakeAsync, package dart:async, package dart:async-patch, and package stack_trace)

This was caught by the test expectation on the following line:
  file:///Users/pankajsahdevea/Desktop/HD/Work/Haufe/Code/IF2.0/if_ui_Sep13,2019/test/widget_test/dashboard/feedback/feedback_list/ui/feedback_list_test.dart line 45
The test description was:
  validate Feedback List widget
════════════════════════════════════════════════════════════════════════════════════════════════════

Test failed. See exception logs above.
The test description was: validate Feedback List widget
test/widget\u test/dashboard/feedback/feedback\u list/ui/feedback\u list\u test.dart
══╡ 颤振测试框架捕获异常╞════════════════════════════════════════════════════
运行测试时引发了以下TestFailure对象:
预期:小部件树中只有一个匹配节点
实际值:_WidgetTypeFinder:
这意味着除了预期的一个之外,没有找到任何对象
引发异常时,这是堆栈:
#4主要。。(file:///Users/pankajsahdevea/Desktop/HD/Work/Haufe/Code/IF2.0/if_ui_Sep132019/test/widget\u test/dashboard/feedback/feedback\u list/ui/feedback\u list\u test.dart:45:7)
#5个测试小部件。。(包装:颤振测试/src/widget测试仪。dart:124:25)
#6 TestWidgetsFlutterBinding.\u runTestBody(包:flutter\u test/src/binding.dart:696:19)
#9 TestWidgetsFlutterBinding.\u runTest(包:flutter\u test/src/binding.dart:679:14)
#10 AutomatedTestWidgetsFlutterBinding.runTest。(包装:颤振试验/src/binding.dart:1050:24)
#16 AutomatedTestWidgetsFlutterBinding.runTest(包:颤振测试/src/binding.dart:1047:15)
#17个小部件。(包装:颤振测试/src/widget测试仪。dart:121:22)
#18庄家。测试。。。(软件包:test_api/src/backend/declarer.dart:171:27)
#19 Invoker.waitforOutstanding回调。(包:test_api/src/backend/invoker.dart:242:15)
#24 Invoker.waitForOutstandingCallbacks(包:test_api/src/backend/Invoker.dart:239:5)
#25庄家测试。。(软件包:test_api/src/backend/declarer.dart:169:33)
#30庄家测试。(包:test_api/src/backend/declarer.dart:168:13)
#31调用程序。\u onRun。。。。(包:testapi/src/backend/invoker.dart:392:25)
#45计时器和运行计时器(dart:isolate patch/Timer\u impl.dart:384:19)
#46 _Timer._handleMessage(dart:隔离补丁/计时器_impl.dart:418:5)
#47 _RawReceivePortImpl._handleMessage(dart:隔离补丁/隔离补丁。dart:174:12)
(从类_FakeAsync、包dart:async、包dart:async patch和包堆栈_trace中删除了28帧)
这被以下行上的测试预期所捕获:
file:///Users/pankajsahdevea/Desktop/HD/Work/Haufe/Code/IF2.0/if_ui_Sep132019/test/widget\u test/dashboard/feedback/feedback\u list/ui/feedback\u list\u test.dart行45
试验说明如下:
验证反馈列表小部件
════════════════════════════════════════════════════════════════════════════════════════════════════
测试失败。请参阅上面的异常日志。
测试描述是:验证反馈列表小部件