5

How to run multiple test cases of Flutter integration tests in single command or from single file. 1. If I run two separate commands for two files then report generates only for last command. 2. When I try to do separate groups in single file then app stays on same page doesn't restart.

Here I need to restart app for further processing. Is there any way to combine multiple test cases to run from multiple files.?

Thing to consider: I am using ozzie as a report generator.

Thanks in advance.

Vitthal Bobade
  • 356
  • 3
  • 12
  • 1
    Have you tried calling separate groups from main function? – iLion Nov 22 '19 at 06:36
  • 1
    Yes, I have tried but no luck. – Vitthal Bobade Nov 22 '19 at 06:36
  • 1
    Athough I haven't played with ozzie yet, that sounds like an issue with the report generator. Have you tried to run the default command from terminal where we pass the test file that has multiple test cases ? Currently there's no way to run tests from multiple files in one single command, but you can provide respective test file name directly in the terminal and flutter driver will execute it one after other in sequence. Ex : `flutter drive — target=test_driver/app.dart — driver=test_driver/app_test.dart` `flutter drive — target=test_driver/app.dart — driver=test_driver/home_test.dart` – Darshan Nov 22 '19 at 07:37
  • 1
    Thanks @Darshan for the information. I tried same it works for tests but due to ozzie report was generated for last command only. – Vitthal Bobade Nov 26 '19 at 05:47
  • That may be an issue with ozzie report tool. You may open a bug against it. As a workaround, if it's applicable in your setup, try to execute test directly from terminal. – Darshan Nov 27 '19 at 06:22
  • Does this answer your question? [Can I run multiple integration tests with one single config file in Flutter?](https://stackoverflow.com/questions/56236606/can-i-run-multiple-integration-tests-with-one-single-config-file-in-flutter) – Jannie Theunissen Jan 12 '21 at 15:54

1 Answers1

5

You may trying to run all test-case from one file. it may help, though its late replay.

Suppose you have 3 test file which is,

  1. login.dart and login_test.dart (where all the test-case has to be written in login_test.dart)
  2. register.dart and register_test.dart
  3. forgotPassword.dart and forgotPassword_test.dart

Put all those test-cases into a main function. (describing only one test file code[login_test.dart])

main(){
  loginTest();

}
Future<void> loginTest()async{

  group('Login Page Automation Test :', () {

//Write your test-cases here

}

so, now create a test file and call all the main functions on that file, which will be used to run all cases at once.

testAll.dart & testAll_test.dart

Write in these format on testAll_test.dart

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


import 'login_test.dart';
import 'register_test.dart';
import 'forgotPassword_test.dart';



main() {
  testAll();
}

Future<void> testAll() async {
  group('All TestCase at Once: ', () {

    //code here

    FlutterDriver driver;
    // Connect to the Flutter driver before running any tests.
    setUpAll(() async {
      driver = await FlutterDriver.connect();
    });

    // Close the connection to the driver after the tests have completed.
    tearDownAll(() async {
      if (driver != null) {
        driver.close();
      }
    });

    //main methods below

    forgotPasswordTest();

    registerTest();

    loginTest();


  });
}

and finally run the app using this.

flutter drive --target=test_driver/testAll.dart
Mahmud Oni
  • 51
  • 1
  • 6