2

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?

Burhanuddin Rashid
  • 5,260
  • 6
  • 34
  • 51

2 Answers2

5

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
jignesh.world
  • 1,396
  • 1
  • 11
  • 26
0

There is now a better way of doing it. Just use the test command like this.

To run all test

flutter test integration_test

To run a specific test

flutter test integration_test/app_test.dart

Reference.

Burhanuddin Rashid
  • 5,260
  • 6
  • 34
  • 51
  • 1
    CI servers like AppCenter or Firebase will not run this command - there is no direct connection through adb. You must build and provide app.apk and app-test.apk files. Accepted Answer solves CI use-case – Etruskas Oct 12 '21 at 12:38