5

I am trying to run my integration test on Firebase Test Lab.

flutter build apk -t lib/main_dev.dart
./gradlew app:assembleAndroidTest -Ptarget=lib/main_dev.dart
./gradlew app:assembleDebug -Ptarget=integration_test/login_test.dart

This code generates app-debug-androidTest.apk and app-debug.apk and once I upload them in Test Lab Test are executed perfectly.

Now the issue is I have many test files under integration_test. I am not sure how to create a app-debug-androidTest.apk that includes all the testcases under integration_test.

I did try the following:

flutter build apk -t lib/main_dev.dart
./gradlew app:assembleAndroidTest -Ptarget=lib/main_dev.dart
./gradlew app:assembleDebug -Ptarget=test_driver/integration_test.dart

but this stuck test at black screen which is I thing weird but a correct behavior as while running the integration test in local device also we need to provide target along with the driver.

So for Local I have a script

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

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

which runs the all the Integration code.

So my question is how to upload all the test cases.

Or do we have to make build for each test case

./gradlew app:assembleDebug -Ptarget=integration_test/login_test.dart

then upload it to the Test Lab then again

./gradlew app:assembleDebug -Ptarget=integration_test/register_test.dart

and upload again?

Asis
  • 683
  • 3
  • 23

2 Answers2

3

I have just encountered the same issue. For future reference for other people, what I did was to import all the tests into one single file all_tests.dart.

Let's say the directory structure is

integration_test/
  test1.dart
  test2.dart
  test3.dart
  all_tests.dart

In all_tests.dart, I imported all the tests in:

import 'test1.dart' as test1;
import 'test2.dart' as test2;

void main() {
  test1.main();
  test2.main();
  ...
}
Dharman
  • 30,962
  • 25
  • 85
  • 135
Anh Pham
  • 695
  • 1
  • 6
  • 21
  • Is this working? I get to launch only the first file, then I get "All tests passed." and the other are skipped. – Leonardo Aug 12 '21 at 08:50
  • EDIT: It actually works, but not if you're using the screenshot approach explained here: https://github.com/flutter/flutter/tree/master/packages/integration_test#screenshots – Leonardo Aug 12 '21 at 08:59
  • It's not working for me, it is said "No tests found". Could you share a more detailed gist? Btw it's only working on flutter integration test (flutter drive) – TijaniRF Jul 28 '22 at 11:50
  • With the new flutter integration test, you can run the whole folder I think. Just need to specify the directory, that's it. @TijaniRF – Anh Pham Aug 03 '22 at 06:52
  • @AnhPham it is indeed working if I run it from Vscode, all of the integration tests are running. But it is not working if I used the instrumentation test as the OP specified – TijaniRF Aug 09 '22 at 12:48
  • 1
    This approach didn't work for us. Even when running couple of test files together. While running the big suite with `flutter test integration_test/` we observed that between test run there is an additional build happening, while slow that step is creating reliability – satyajit Aug 29 '22 at 21:32
  • 1
    Appending the above comment, I was able to get rid of flakiness by creating additional groups within tests. We had setup/teardown with getit DI setup and that was getting messed up without group. – satyajit Aug 30 '22 at 22:01
1

I had the same kind of problem where there was no real way to get back to a clean app state after a test was run. Clearing the app data between the tests helped me a lot.

With

import 'dart:io';
import 'package:path_provider/path_provider.dart';
tearDown(() async {
  final filesDirPath = (await getApplicationSupportDirectory()).path;
  if (Directory(filesDirPath).existsSync()) {
    await Directory(filesDirPath).delete(recursive: true);
  }
});

There could be more directories to remove like getTemporaryDirectory(), but this is usually where the user data is saved.