Flutter - Executing the integration test launches default app instead of the test

74 Views Asked by At

Okay, this is a bit of weird issue for me. I was working on an integration test for a client and the client made an update on the app to have different (flutter) build flavor - which I didn't notice until I did a git pull. Now, this for me is a checkpoint. Because after this - I was not able to run the integration - I mean it runs but it launches the default app as if I run the main.dart file. I'm not sure as to why this is happening. I configured my launch json to execute the flavors (which are main_dev.dart and main_prod.dart) but I don't understand why I'm not able to run the integration test. Here is how the build.gradle file looks like (for the flavors)

android {

    ...

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }

    flavorDimensions "env"
    productFlavors {
        dev {
            dimension "env"
            applicationId "com.example.app"
        }
        prod {
            dimension "env"
            applicationId "com.example.app"
        }
    }
}

based on the above configuration there are 3 files - the main.dart, main_dev.dart, and main_prod.dart. I'm using vscode and the launch.json file looks like this:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "NewAppJun29",
            "request": "launch",
            "type": "dart",
            "args": [
                "-t",
                "lib/main_prod.dart",
                "--flavor",
                "prod"
            ]
        },
        {
            "name": "dev",
            "request": "launch",
            "type": "dart",
            "args": [
                "-t",
                "lib/main_dev.dart",
                "--flavor",
                "dev"
            ]
        },
       
    ]
}

To give you an idea - my integration test looks like this:

...
void main() {
  IntegrationTestWidgetsFlutterBinding.ensureInitialized();

  late AuthRobot authRobot;
  late ProfileRobot profileRobot;

  group('Flutter integration test', () {
    testWidgets('End user flow - ECOM', (widgetTester) async {
      app.main();

      await widgetTester.pumpAndSettle(Duration(seconds: 5));

      homeRobot = HomeRobot(widgetTester);
      profileRobot = ProfileRobot(widgetTester);

      await authRobot.enterEmail('[email protected]');
      await authRobot.enterPassword('Test@1234');
      await authRobot.tapLoginButton();

      await widgetTester.pump();
      await widgetTester.idle();
      await widgetTester.pumpAndSettle();
      ...
   },
 });
}

Can anyone tell me how to fix this and why is this happening?

1

There are 1 best solutions below

0
Balaji On

In Android Studio,

enter image description here

GoTo Run/Debug Configurations

Add New Flutter Test

and add your flavor --flavor=[YOUR_FLAVOR] in the Additional args:

Then run

or USING COMMAND

flutter test integration_test/app_test.dart --flavor=dev

for VSCode

add this

 {
        "name": "Flutter Integration Test (Dev Flavor)",
        "request": "launch",
        "type": "dart",
        "program": "integration_test/app_test.dart", // your integration test folder / your test_file.dart
        "args": [
          "--flavor=dev"
        ],
      }

in launch.json