Flutterando / slidy

CLI package manager and template for Flutter
https://pub.dev/packages/slidy
Apache License 2.0
803 stars 101 forks source link

home_page_test.dart failing on new project #149

Closed isorensen closed 4 years ago

isorensen commented 4 years ago

Summary

When creating a new project using slidy with modular/mobx, flutter test fails in HomePage has title test

Steps to reproduce

  1. Create a new project using slidy, with modular/mobx
  2. run flutter test

Logs

HomePage has title:

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following ModularError was thrown building Builder:
HomeController not found

The relevant error-causing widget was:
  MaterialApp
  file:///Applications/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_modular-1.2.1/lib/src/test/utils_test.dart:34:12

When the exception was thrown, this was the stack:
#0      Modular.get (package:flutter_modular/src/modular_base.dart:117:5)
#1      new ModularState (package:flutter_modular/src/widgets/modular_stateful_widget_state.dart:6:30)
#2      new _HomePageState (package:okr_os/app/modules/home/home_page.dart)
#3      HomePage.createState (package:okr_os/app/modules/home/home_page.dart:10:35)
#4      new StatefulElement (package:flutter/src/widgets/framework.dart:4591:25)
#5      StatefulWidget.createElement (package:flutter/src/widgets/framework.dart:894:38)
...     Normal element mounting (115 frames)
#120    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3446:14)
#121    MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5947:32)
...     Normal element mounting (253 frames)
#374    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3446:14)
#375    Element.updateChild (package:flutter/src/widgets/framework.dart:3211:20)
#376    RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:1148:16)
#377    RenderObjectToWidgetElement.update (package:flutter/src/widgets/binding.dart:1126:5)
#378    RenderObjectToWidgetElement.performRebuild (package:flutter/src/widgets/binding.dart:1140:7)
#379    Element.rebuild (package:flutter/src/widgets/framework.dart:4218:5)
#380    BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2627:33)
#381    AutomatedTestWidgetsFlutterBinding.drawFrame (package:flutter_test/src/binding.dart:1006:18)
#382    RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:284:5)
#383    SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1113:15)
#384    SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1052:9)
#385    AutomatedTestWidgetsFlutterBinding.pump.<anonymous closure> (package:flutter_test/src/binding.dart:879:9)
#388    TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:72:41)
#389    AutomatedTestWidgetsFlutterBinding.pump (package:flutter_test/src/binding.dart:866:27)
#390    WidgetTester.pumpWidget.<anonymous closure> (package:flutter_test/src/widget_tester.dart:441:22)
#393    TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:72:41)
#394    WidgetTester.pumpWidget (package:flutter_test/src/widget_tester.dart:438:27)
#395    main.<anonymous closure> (file:///Users/eduardosorensen/Documents/iDev.nosync/Credifit/okr_os/test/app/modules/home/home_page_test.dart:11:18)
#396    main.<anonymous closure> (file:///Users/eduardosorensen/Documents/iDev.nosync/Credifit/okr_os/test/app/modules/home/home_page_test.dart:10:37)
#397    testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:140:29)
#410    AutomatedTestWidgetsFlutterBinding.runTest.<anonymous closure> (package:flutter_test/src/binding.dart:1099:17)
#411    AutomatedTestWidgetsFlutterBinding.runTest.<anonymous closure> (package:flutter_test/src/binding.dart:1087:35)
(elided 31 frames from class _FakeAsync, dart:async, and package:stack_trace)

════════════════════════════════════════════════════════════════════════════════════════════════════
══╡ 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: _TextFinder:<zero widgets with text "Home" (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> (file:///Users/eduardosorensen/Documents/iDev.nosync/Credifit/okr_os/test/app/modules/home/home_page_test.dart:13:5)
<asynchronous suspension>
#5      main.<anonymous closure> (file:///Users/eduardosorensen/Documents/iDev.nosync/Credifit/okr_os/test/app/modules/home/home_page_test.dart)
#6      testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:140:29)
<asynchronous suspension>
#7      testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart)
#8      TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:703:19)
<asynchronous suspension>
#11     TestWidgetsFlutterBinding._runTest (package:flutter_test/src/binding.dart:683:14)
#12     AutomatedTestWidgetsFlutterBinding.runTest.<anonymous closure> (package:flutter_test/src/binding.dart:1083:24)
#18     AutomatedTestWidgetsFlutterBinding.runTest (package:flutter_test/src/binding.dart:1080:15)
#19     testWidgets.<anonymous closure> (package:flutter_test/src/widget_tester.dart:133:24)
#20     Declarer.test.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/declarer.dart:172:27)
<asynchronous suspension>
#21     Declarer.test.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/declarer.dart)
#22     Invoker.waitForOutstandingCallbacks.<anonymous closure> (package:test_api/src/backend/invoker.dart:246:15)
#27     Invoker.waitForOutstandingCallbacks (package:test_api/src/backend/invoker.dart:243:5)
#28     Declarer.test.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/declarer.dart:170:33)
#33     Declarer.test.<anonymous closure> (package:test_api/src/backend/declarer.dart:169:13)
#34     Invoker._onRun.<anonymous closure>.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/invoker.dart:400:30)
(elided 31 frames from class _FakeAsync, class _RawReceivePortImpl, class _Timer, dart:async, dart:async-patch, and package:stack_trace)

This was caught by the test expectation on the following line:
  file:///Users/eduardosorensen/Documents/iDev.nosync/Credifit/okr_os/test/app/modules/home/home_page_test.dart line 13
The test description was:
  HomePage has title
════════════════════════════════════════════════════════════════════════════════════════════════════
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following message was thrown:
Multiple exceptions (2) were detected during the running of the current test, and at least one was
unexpected.
════════════════════════════════════════════════════════════════════════════════════════════════════
ERROR: Test failed. See exception logs above.
The test description was: HomePage has title

Possible fix

When initializing both AppModule and HomeModule after main(), test passes.

import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_modular/flutter_modular_test.dart';
import 'package:okr_os/app/app_module.dart';
import 'package:okr_os/app/modules/home/home_module.dart';
import 'package:okr_os/app/modules/home/home_page.dart';

main() {
// LINES ADDED
  initModule(AppModule());
  initModule(HomeModule());
// END
  testWidgets('HomePage has title', (tester) async {
    await tester.pumpWidget(buildTestableWidget(HomePage(title: 'Home')));
    final titleFinder = find.text('Home');
    expect(titleFinder, findsOneWidget);
  });
}

So, I think they should be added by default in test file creating.