Dart-code: Support running/debugging Flutter Driver integration tests

Created on 7 Jul 2020  路  7Comments  路  Source: Dart-Code/Dart-Code

I'm working through this guide trying to get to a point where I can step through driver scripts and/or driven apps in VSCode: https://medium.com/flutter-community/hot-reload-for-flutter-integration-tests-e0478b63bd54

Running the terminal commands works, but I haven't been able to get either side to work when launched from VSCode yet. There seem to be two things in the way:

  • Setting a known --observation-port via "args" in launch.json seems to get overridden by the extension
  • There doesn't seem to be any way to run the driver program as a dart CLI command because the extension detects the project type from the workspace folder and offers no launch.json-level override. It gets launched on the Android device I just launched the app on, and I can breakpoint through it but it kills the app on the device to launch the driver

Here's my best guess so far:

    {
      "name": "Integration Tests: Launch App",
      "request": "launch",
      "type": "dart",
      "program": "test_driver/app.dart",
      "args": [
        "--dart-define=app.api=http://10.0.2.2:5378/api/v1", // special android IP for host, works
        "--observatory-port 4567", // doesn't seem to work
        "--disable-service-auth-codes"
      ],
      "flutterMode": "debug", // don't know if needed
    },
    {
      "name": "Integration Tests: Launch Driver",
      "request": "launch",
      "type": "dart",
      "program": "test_driver/app_test.dart",
      "deviceId": null, // this needs to run on the host computer, but it wants to run on the same device as the app
      "env": {
        "VM_SERVICE_URL": "http://127.0.0.1:4567"
      },
    },
in debugger in flutter in testing is enhancement

Most helpful comment

Could you try this version out for me?

  • Download the.vsix file from https://github.com/Dart-Code/Dart-Code/releases/tag/v3.13.0-alpha.2~~
  • Run the Extensions: Install from VSIX command from the VS Code command palette
  • Browse to the file you downloaded
  • Click the Restart button when prompted
  • Remove your launch.json
  • Open test_driver/app.dart and press F5 - this should now launch this file (the instrumented version)
  • Wait for the app to launch
  • Switch to test_driver.app_test.dart
  • Press F5 to run the whole file, or use the CodeLens Run/Debug links to run individual tests

This should give you full debugging of both the app and the test, and you shouldn't need to mess around with launch configs. If you do want to be able to launch these from launch configs, you should be able to just strip out all the args/env you added:

 {
      "name": "Integration Tests: Launch App",
      "request": "launch",
      "type": "dart",
      "program": "test_driver/app.dart",
    },
    {
      "name": "Integration Tests: Launch Driver",
      "request": "launch",
      "type": "dart",
      "program": "test_driver/app_test.dart",
    },

Let me know if this seems to work ok for you (I've never used driver tests before, so I'm flying a little blind here). If you hit any issues, let me know (ether here, or once this issue is closed, in new issues). If it all works, you can remain on this test version and when the next stable release goes out you'll be automatically changed over to it (if you have auto updates for extensions enabled).

BTW - I made it automatically Hot Restart the app at the start of the test run, as it seemed weird to run with existing state.. if this feels weird, let me know (I did it because the sample tests here would fail if run multiple times due to the counter state not being reset).

All 7 comments

Could you try this version out for me?

  • Download the.vsix file from https://github.com/Dart-Code/Dart-Code/releases/tag/v3.13.0-alpha.2~~
  • Run the Extensions: Install from VSIX command from the VS Code command palette
  • Browse to the file you downloaded
  • Click the Restart button when prompted
  • Remove your launch.json
  • Open test_driver/app.dart and press F5 - this should now launch this file (the instrumented version)
  • Wait for the app to launch
  • Switch to test_driver.app_test.dart
  • Press F5 to run the whole file, or use the CodeLens Run/Debug links to run individual tests

This should give you full debugging of both the app and the test, and you shouldn't need to mess around with launch configs. If you do want to be able to launch these from launch configs, you should be able to just strip out all the args/env you added:

 {
      "name": "Integration Tests: Launch App",
      "request": "launch",
      "type": "dart",
      "program": "test_driver/app.dart",
    },
    {
      "name": "Integration Tests: Launch Driver",
      "request": "launch",
      "type": "dart",
      "program": "test_driver/app_test.dart",
    },

Let me know if this seems to work ok for you (I've never used driver tests before, so I'm flying a little blind here). If you hit any issues, let me know (ether here, or once this issue is closed, in new issues). If it all works, you can remain on this test version and when the next stable release goes out you'll be automatically changed over to it (if you have auto updates for extensions enabled).

BTW - I made it automatically Hot Restart the app at the start of the test run, as it seemed weird to run with existing state.. if this feels weird, let me know (I did it because the sample tests here would fail if run multiple times due to the counter state not being reset).

@DanTup it works!!! this is brilliant

Great, thanks for confirming!

@DanTup how long does it usually take for new versions to show up at https://marketplace.visualstudio.com/items?itemName=Dart-Code.dart-code

@themightychris this feature isn't included in a release yet - it'll be in the version in the assigned milestone (v3.13.0) which is likely to ship around the end of the month (there was a release today, but it was a minor version to support using the Flutter SDK Snap). The issues are automatically closed when the work is merged to master.

For now, you should stick with the preview build from above - if you have auto-updates on, VS Code will automatically upgrade you to the stable v3.13.0 when it's published.

I'm working through this guide trying to get to a point where I can step through driver scripts and/or driven apps in VSCode: https://medium.com/flutter-community/hot-reload-for-flutter-integration-tests-e0478b63bd54

Running the terminal commands works, but I haven't been able to get either side to work when launched from VSCode yet. There seem to be two things in the way:

  • Setting a known --observation-port via "args" in launch.json seems to get overridden by the extension
  • There doesn't seem to be any way to run the driver program as a dart CLI command because the extension detects the project type from the workspace folder and offers no launch.json-level override. It gets launched on the Android device I just launched the app on, and I can breakpoint through it but it kills the app on the device to launch the driver

Here's my best guess so far:

    {
      "name": "Integration Tests: Launch App",
      "request": "launch",
      "type": "dart",
      "program": "test_driver/app.dart",
      "args": [
        "--dart-define=app.api=http://10.0.2.2:5378/api/v1", // special android IP for host, works
        "--observatory-port 4567", // doesn't seem to work
        "--disable-service-auth-codes"
      ],
      "flutterMode": "debug", // don't know if needed
    },
    {
      "name": "Integration Tests: Launch Driver",
      "request": "launch",
      "type": "dart",
      "program": "test_driver/app_test.dart",
      "deviceId": null, // this needs to run on the host computer, but it wants to run on the same device as the app
      "env": {
        "VM_SERVICE_URL": "http://127.0.0.1:4567"
      },
    },

Hi @themightychris, you mention here that you can use --dart-define inside args. I already tried but it's not working on the test driver, it is only working on my default app. Are there any gotchas that I need to carefully check?

@tijanirf it's all super easy to do now, and built into the vscode extension. You don't need to pass --observatory-port or --disable-service-auth-codes in launch.json, you just need to launch the driver-wrapped version of your app from launch.json, and then when you open up your test suite in vscode the editor will be decorated with Run | Debug buttons at various scopes, just click them while you have the instrumented app running from vscode and it should all Just Work!

Was this page helpful?
0 / 5 - 0 ratings