Show menu

test_driver/app.dart

  import 'package:flutter_driver/driver_extension.dart';
  import 'package:counter_app/main.dart' as app;

  void main() {
    enableFlutterDriverExtension();

    app.main();
  }
  

test_driver/app_test.dart

  import 'package:flutter_driver/flutter_driver.dart';
  import 'package:test/test.dart';

  void main() {
    group("Counter app test", () {
      final counterText = find.byValueKey("counter");
      final incrementButton = find.byValueKey("increment");
      final decrementButton = find.byValueKey("decrement");

      late final FlutterDriver driver;

      setUpAll(() async {
        driver = await FlutterDriver.connect();
      });

      tearDownAll(() async {
        driver.close();
      });

      test("Counter increment", () async {
        await driver.tap(incrementButton);

        final readText = await driver.getText(counterText);
        expect(readText, "1");
      });

      test("Counter increment", () async {
        await driver.tap(decrementButton);

        final readText = await driver.getText(counterText);
        expect(readText, "0");
      });
    });
  }
  

This website and the book are not official Google products. No affiliations are involved. Built with Java 14 and Vert.X

"Flutter and the related logo are trademarks of Google LLC. We are not endorsed by or affiliated with Google LLC"