VS Code does not recognize unit tests in Flutter
Solution 1
Make sure you name you test file ending with _test.dart
and you will see the run | debug options
Solution 2
I have a Flutter project with two separate test files, both ending in "..._test.dart".
Using the following two test scenarios, one of the files passes, while the second doesn't load and that test fails.
Using launch.json configuration:
{
"name": "Dart: Run all Tests",
"request": "launch",
"type": "dart",
"program": "./test/"
}
Using the VS Code menu item Debug > Start Debugging (F5)
, which I suspicion just uses the above launch.json configuration, yields the same result.
However, using the VS Code menu item Debug > Start Without Debugging (Ctrl+F5)
, or "flutter test" from the command line, both tests pass.
I suspect this is an internal configuration issue with the VS Code Dart/Flutter extension, as opposed to a problem with Dart/Flutter code structure.
Solution 3
Are your tests/groups spread across multiple files? There are some limitations to the integration between the VS Code extension and the test package that you may be hitting.
There was a fix in v2.23 (released a few days before your question) that should have improved this a little (removing those Run/Debug links in some places they wont' work) but if you're already on that version then maybe it didn't cover your case.
If you can post a small repro on GitHub I'd definitely like to see if I can improve this. Thanks!
jarekbutek
Updated on December 09, 2022Comments
-
jarekbutek over 1 year
Visual Studio Code does not recognize unit tests grouped in
group(...)
. But it recognizes unit tests which are not grouped. I mean they are standalonetest(...)
. I want to use group, because I needsetUp()
.There is
Run | Debug
link abovegroup
. When I click Debug or Run the Debug console showsNo tests match regular expression "^LocalRepository$".
The tests are running correctly with
flutter test
command.Dart SDK: >=2.1.0 <3.0.0
Flutter channel: master
Edit: I found workaround - I just don't use
group
callback. But I can't run all tests by clickingRun
abovegroup
.