Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New integration_test package just shows "Test starting..." [Android]

I tried to migrate my old flutter driver tests to the new integration_test package. I copied nearly everything from the example project and executed the integration tests of the example project locally. That worked as expected, I was able to see the app UI. But my own app just shows "Test starting..." in a purple color after the splash screen was shown.

example_test.dart:

void main() {
  group('My-App', () {
    final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized() as IntegrationTestWidgetsFlutterBinding;

    testWidgets('Tap on SkipAuthentication', (tester) async {
      app.main();

      await binding.traceAction(() async {
        await tester.pumpAndSettle();

        await Future.delayed(Duration(seconds: 5));

        final fab = find.byKey(ValueKey(WidgetKeys.authenticationScreenKeys.skipAuthenticationButton));
        await tester.tap(fab);

        await tester.pumpAndSettle();
      });
    });



integration_driver.dart:

Future<void> main() async {
  integrationDriver();
}

I figured out, that if I don't start the tester.pumpWidget() shows the Widget, that I pass to the method, but thats a WidgetTest and not an integration Test.

My guess is, that it's due to the fact that my main function is an async function. I also needed this workaround in my old flutter driver tests to wait for the first frame. But I couldn't figure out how to implement that with the new integration_test package.

Hope you can help me.

like image 335
Andreas B. Avatar asked Dec 22 '20 17:12

Andreas B.


People also ask

What is integration testing in ASP NET?

Integration tests ensure that an app's components function correctly at a level that includes the app's supporting infrastructure, such as the database, file system, and network. ASP.NET Core supports integration tests using a unit test framework with a test web host and an in-memory test server.

What is the difference between widget testing and integration testing?

A widget test verifies the behavior of Flutter widgets without running the app itself. An integration test (also called end-to-end testing or GUI testing) runs the full app.

Why is the testhost and testserver package not in the project file?

Because the Microsoft.AspNetCore.Mvc.Testing package is used to configure the test host and test server, the TestHost and TestServer packages don't require direct package references in the test app's project file or developer configuration in the test app.

What is the integration_test plugin?

One of the major advancements of the integration_test plugin is the ability to run your Flutter apps targeting Android and iOS on Firebase Test Lab, giving you the ability to test across hundreds of devices simultaneously in order to find platform, form factor, or device-specific issues before shipping your app.


Video Answer


3 Answers

Huh. I started converting my flutter_driver tests over the holidays and ran into the same thing.

My fix was to add a fixed sleep after launching the test, which allowed it to initialize properly. So one test case looks like this:

    testWidgets("Main screen loads", (WidgetTester widgetTester) async {
      app.main();
      await sleep(Duration(seconds: 10));
      await widgetTester.pumpAndSettle();

      expect(find.text("What are you looking for?"), findsOneWidget);
    });
like image 156
Zalán Meggyesi Avatar answered Oct 21 '22 08:10

Zalán Meggyesi


I had this issue also and the sleep / Future.delayed did not work. Some times the integration tests were run but mostly they were not.

What ultimately fixed the issue for me was to change the framePolicy of IntegrationTestWidgetsFlutterBinding to LiveTestWidgetsFlutterBindingFramePolicy.fullyLive. Here is a full example:

void main() {
  final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized()
      as IntegrationTestWidgetsFlutterBinding;

  binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fullyLive;

  testWidgets("failing test example", (WidgetTester tester) async {
    app.main();
    await tester.pumpAndSettle();

    // Start testing here...
  });
}

The solution was found from Google Codelabs.

like image 27
vkopio Avatar answered Oct 21 '22 08:10

vkopio


I was struggling with this also for some hours and finally found the answer.

Your issue is that do not pump a widget with await tester.pumpWidget(MyApp())

Your test look like:

void main() {
    testWidgets('Tap on SkipAuthentication', (tester) async {
      app.main(); // <--- You call app.main() - This Flutter Driver style, but not integration test style

      await binding.traceAction(() async {
        await tester.pumpAndSettle();

        await Future.delayed(Duration(seconds: 5));

        final fab = find.byKey(ValueKey(WidgetKeys.authenticationScreenKeys.skipAuthenticationButton));
        await tester.tap(fab);

        await tester.pumpAndSettle();
      });
    });

You need to change your test like this:

void main() {
  testWidgets('Tap on SkipAuthentication', (tester) async {
    await tester.pumpWidget(MyApp()); // You need to call await tester.pumpWidget();
    await tester.pump(const Duration(seconds: 1));

    final fab = find.byKey(ValueKey(WidgetKeys.authenticationScreenKeys.skipAuthenticationButton));
    await tester.tap(fab);

    await tester.pump();
  });
}
like image 39
Nils Reichardt Avatar answered Oct 21 '22 09:10

Nils Reichardt