Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Code does not recognize unit tests in Flutter

Visual Studio Code does not recognize unit tests grouped in group(...). But it recognizes unit tests which are not grouped. I mean they are standalone test(...). I want to use group, because I need setUp().

There is Run | Debug link above group. When I click Debug or Run the Debug console shows No 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 clicking Run above group.

like image 542
jarekbutek Avatar asked Feb 19 '19 08:02

jarekbutek


Video Answer


2 Answers

Make sure you name you test file ending with _test.dart and you will see the run | debug options

like image 137
user3753092 Avatar answered Oct 06 '22 19:10

user3753092


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.

like image 22
Norton Newmann Avatar answered Oct 06 '22 19:10

Norton Newmann