Repository navigation
Evaluate code in Debug Console during integration tests #4206
Copy link
Copy link
Closed
Labels
in flutterRelates to running Flutter appsRelates to running Flutter appsin testingRelates to test execution of Dart/Flutter tests for end usersRelates to test execution of Dart/Flutter tests for end usersis enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.An enhancement or improvement that should be listed in release notes but is not a bug fix.
Milestone
Description
Describe the bug
TL;DR I can't evaluate code in Debug Console when running integration tests. I don't know if I'm doing something wrong or if this is just not possible.
Also, I can't find a way to run (using VS Code's launch.json) normal widget tests with flutter run test/widget_test.dart (=running on device) instead of flutter test test/widget_test.dart (running in isolation). This might be another issue, though.
To Reproduce
TL;DR Run any Flutter integration test with VS Code and try to evaluate Dart code in the Debug Console.
Create .vscode/launch.json in the root of a Flutter project with the following contents:
{
"version": "0.2.0",
"configurations": [
{
"name": "flutter run app",
"request": "launch",
"type": "dart",
"program": "lib/main.dart"
},
{
"name": "flutter run integration tests",
"request": "launch",
"type": "dart",
"program": "integration_test/example_test.dart"
},
]
}- Clone the repository of the Patrol framework
- Open the example app directory with VS Code (
$ code .). It's located inpackages/patrol/example - Now that you're in the example app's dir, put a breakpoint somewhere in the integration_test/example_test.dart file, for example on line 16:
await $(FloatingActionButton).tap();
- Run the
flutter run integration testsconfiguration fromlaunch.json - Try to evaluate some code in the Debug Console.
- See
_compileExpression: No compilation service available; cannot evaluate from source..
Expected behavior
Being able to evaluate Dart code in Debug Console when the test is stopped on a breakpoint.
This is how it works with widget tests running in isolation:
Running.widget.test.in.isolation.mov
System info
- Operating System and version: macOS 12.6 on MacBook Air M1
- VS Code version: 1.72.0
- Dart extension version: v3.50.0
- Dart/Flutter SDK version: Dart 2.18.2, Flutter 3.3.3
- Target device: Android emulator (Pixel 5 API 33)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
in flutterRelates to running Flutter appsRelates to running Flutter appsin testingRelates to test execution of Dart/Flutter tests for end usersRelates to test execution of Dart/Flutter tests for end usersis enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.An enhancement or improvement that should be listed in release notes but is not a bug fix.

Activity
[-]How can I get evaluate code in Debug Console in tests?[/-][+]Evaluate code in Debug Console during integration tests[/+]DanTup commentedon Oct 7, 2022
This is unfortunately a known limitation. It requires work in Flutter to hook up an compilation service for expression evaluation. There's an issue tracking that at flutter/flutter#79439.
You can do this by adding
"runTestsOnDevice": trueto yourlaunch.jsonto run normal tests on a device.You can also set this up to add additional CodeLens links with something like this:
This will add additional "Run on Device" and "Debug on Device" links above the
mainfunction in your test files:This is only possible for the whole file (not individual tests), because
flutter runis not able to run individual tests/groups.Hope this helps!
bartekpacia commentedon Oct 7, 2022
Thanks for answering my second little question. Works, indeed :)
But it's sad that we can't evaluate Dart code in Debug Console when running integration tests. I hope this gets implemented soon.
Thanks for your help.
DanTup commentedon Oct 11, 2022
Yeah, I understand. Unfortunately I don't understand how the compilation service works well enough to know whether it's a big change or not. I would encourage adding 👍 's to that Flutter issue if you haven't already.
I'll close this issue as there's actually nothing to do in the VS Code extension. Once implemented in Flutter, it will just start working here.
bartekpacia commentedon Oct 13, 2022
@DanTup Now I got this idea: is it possible to run a test file in the integration test directory with
flutter run, notflutter test?I'm thinking about something like:
{ "version": "0.2.0", "configurations": [ { "name": "run app", "request": "launch", "type": "dart", "program": "lib/main.dart" }, { "name": "run integration test", "request": "launch", "type": "dart", "runTestsOnDevice": true, "executeWithFlutterRun": true, // <-- let's assume that this flag exists "program": "integration_test/example_test.dart" } ] }I haven't found a way to do the above.
In other words: when I run the
run integration testconfiguration, it doesflutter test integration_test/example_test.dart. I'd like to change it to runflutter run -t integration_test/example_test.dartinstead.This would have the following benefits:
Of course, this approach isn't ideal – we'll lose the test reporting ability (and probably more
flutter test-specific functionality.But as a temporary workaround, I think it's an approach worth researching.
DanTup commentedon Oct 15, 2022
@bartekpacia that's essentially what
runTestsOnDevicedoes, however it only currently applies to unit tests (because integration tests already run on a device). We could perhaps add an override here, although it feels kinda clunky and much worse than being fixed in Flutter.Let me ping on that issue and see if anyone can give an idea of the scale of work and pointers to see if it might be something I could contribute there.
DanTup commentedon Oct 15, 2022
Re-opening this as a reminder because I think I have this working but need to come back to it.
bartekpacia commentedon Oct 15, 2022
Thank you very much! 💙
Linking your PR: flutter/flutter#113481
DanTup commentedon Oct 25, 2022
I landed a fix for this in Flutter. It should be available on master now, and in some future stable Flutter SDK release.