4

I've read and tried integration testing with flutter. I followed this guide here...

https://flutter.io/docs/cookbook/testing/integration

Now, to run the integration test I have to type in the following command:

flutter drive --target=test_driver/app.dart

My question is, is there a way to automate this inside android studio so I do not have to type in the command manually. I rather just click one button and run the integration test than type the command over and over again.

I'm new in flutter over all so any suggestion will be very much appreciated. Thanks in advance.

3 Answers 3

5

Not sure if you found answer for your question, but I am going to post solution here. Hope it helps.

  1. In Android Studio, open the run/edit configuration dialog and select Edit Configurations as below:

enter image description here

  1. Click on + button and select Dart Command Line App configuration.

enter image description here

  1. Give a name for the configuration (ex: integration.dart) and select following:

Dart file: the path of the dart file which has integration test. (ex: app_test.dart)

Working directory: root path of your project.

Environment variables: click on folder icon at extreme right in this field and create new environment variable as below:

enter image description here

Note that, the http url will be different in your case. In order to find out that, run the flutter command in terminal and note the observatory url displayed in the console. In my case, it was below:

flutter: Observatory listening on http://127.0.0.1:51150/

Replace it with yours and click OK.

Once you complete above steps properly and run the integration.dart configuration, you should be able to run the command from Android Studio and see the results in IDE.

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

nice one~ Thanks! :D
I tryied this solution, but I got the follow error: VMServiceFlutterDriver: It is taking an unusually long time to connect to the VM. Please, Someone can give some tip how to solve that?
1

I am using Visual Studio and I have created a script file integration_test.sh.

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

..

To execute the test. I just run bash scripts/integration_test.sh

I am also trying to add on launch.json with task.json still could not figure it out. I will update the answer once everything is working.

Code for launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Flutter Dev",
            "program": "lib/main_dev.dart",
            "request": "launch",
            "type": "dart"
        },

        ...

        {
            "name": "Flutter Integration Test",
            "preLaunchTask": "IntegrationTest",
        }
    ]
}

Code for task.json

{
    "version": "0.2.0",
    "tasks":[
        {
            "taskName": "IntegrationTest",
            "command": "scripts/integration_test.sh",
            "isShellCommand": true
        }
    ]
}

Comments

0

Setting up a Run Config with for flutter drive using "Dart Command Line App" requires a VM_SERVICE_URL Environment. If you'd like to let flutter drive create their own VM instance dynamically, you can configure the flutter drive command as an 'External Tool' in Android Studio, and configure created External Tool to run 'Before launch'. Note that the path set on 'Program' points to the Flutter SDK.

flutter drive External Tool config

You can check this GitHub thread for more details.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.