Allow to run entire folder of tests in flutter new integration tests – just like normal unit tests

Issue

I am having a separate integration test file for each screen and I want to run all the integration tests with a single command like “flutter tests”. I looked into the doc but was not able to find any way to do this. This also causes an issue with the firebase test lab apk. To create an android test apk I can only specify a single test file path to create the apk.

// flutter build generates files in android/ for building the app
flutter build apk
./gradlew app:assembleAndroidTest
./gradlew app:assembleDebug -Ptarget=integration_test/whattodo_tests.dart

For now, I found two workarounds for this.

  1. I’ve moved all my tests to a single dart file with a group test.
    But this workaround does not scale well. For the 5-10 test it’s working fine. But let say if we have 50-75 test then it will be a mess to navigate and understand tests in single file.
  2. Create a script to run all tests one by one. This might work on our own CI pipeline, but this won’t work in the firebase test lab.

Does anyone able to solve this issue or any better solution?

Solution

I have came across one project on GitHub has this kind of structure, I think which may help..

Make common file and import different files, folders or modules on that common file for testing

main.dart

import 'package:integration_test/integration_test.dart';
import 'about_us_page_test.dart' as about;
import 'add_label_page_test.dart' as label;
import 'add_project_page_test.dart' as project;
import 'add_task_page_test.dart' as tasks;
import 'completed_tasks_page_test.dart' as tasks_completed;
import 'home_page_test.dart' as home;
import 'whattodo_tests.dart' as whattodo;

void main() {
  IntegrationTestWidgetsFlutterBinding.ensureInitialized();
  whattodo.main();
  home.main();
  tasks.main();
  tasks_completed.main();
  project.main();
  label.main();
  about.main();
}

to run all these tests

flutter drive \
   --driver=test_driver/integration_test_driver.dart \
   --target=integration_test/main.dart

Answered By – jignesh

Answer Checked By – Katrina (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.