简体   繁体   中英

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

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?

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM