Flutter Integration Testing- How to run multiple test cases of Flutter integration tests in single command or from single file
Asked Answered
T

2

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.

Tantalite answered 22/11, 2019 at 6:32 Comment(6)
Have you tried calling separate groups from main function?Sybilsybila
Yes, I have tried but no luck.Tantalite
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.dartRoyroyal
Thanks @Royroyal for the information. I tried same it works for tests but due to ozzie report was generated for last command only.Tantalite
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.Royroyal
Does this answer your question? Can I run multiple integration tests with one single config file in Flutter?Nadabas
D
6

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
Dewan answered 29/8, 2020 at 18:4 Comment(0)
A
0

As an alternative solution, you can still use separate files for each test and then prepare a script (eg. shell) to run them all using a single command. You could use this later in your test automation.

An example of a shell script:

GREEN='\033[0;32m'
NC='\033[0m'
LINE_BREAK="${GREEN} --- ${NC}"

echo "$LINE_BREAK"
echo "${GREEN} TEST 1 ${NC}"
echo "$LINE_BREAK"

# Test 1
flutter drive \
      --driver=test_driver/integration_test.dart \
      --target=integration_test/test_one.dart

echo "$LINE_BREAK"
echo "${GREEN} TEST 2 ${NC}"
echo "$LINE_BREAK"

# Test 2
flutter drive \
      --driver=test_driver/integration_test.dart \
      --target=integration_test/test_suites/test_two.dart

source: https://gist.github.com/md-weber/6b33641ae81696991a044e0041a0f28d

Antagonize answered 6/6 at 8:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.