Add an option to treat '_test.dart' files outside of './test' as tests
See original GitHub issueAs a convention, we are keeping our test files next to our source files instead of in a separate test
directory. Now, when we click “Run” above the test in VSCode, it fails:
Could not find an option named "name".
Run 'flutter -h' (or 'flutter <command> -h') for available flutter commands and options.
Exited (64)
You can reproduce this:
- Create a new Flutter project
- Add a new file
lib/main_test.dart
:
import 'package:flutter_test/flutter_test.dart';
void main() {
test('test test', () {
expect(123, 123);
});
}
- Click “Run” above
test
- Check Debug Console
Is there any way to get this working? If not, how do you recommend structuring the test
directory? We have a very big project and we want to make sure we keep our code organized.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:18 (9 by maintainers)
Top Results From Across the Web
test | Dart Package - Pub.dev
A full featured library for writing and running Dart tests across platforms.
Read more >Dart testing
You can use the test package to: Write single tests, or groups of tests. Use the @TestOn annotation to restrict tests to run...
Read more >DART: Directed Automated Random Testing - People @EECS
cally the execution along alternative program paths. Together, these three techniques constitute Directed Automated Random Testing, or. DART for short.
Read more >Automated Tests in Flutter: Native Tests or Cross-platform ...
Thorough testing needs to have both widget and E2E tests. Widget tests. ... In the _world.dart files, we can add or redefine the...
Read more >Chapter 3. Building and testing your own Dart app
You'll build the PackList app from an entry-point HTML file that hosts the Dart script, and a Dart code file that creates and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sorry for the delay… I was hoping to come up with something better, but haven’t so far.
I’m thinking the simplest way is a setting, something like
dart.allowTestsOutsideTestFolder
. When set tofalse
(the default) it will assume that_test.dart
scripts outside./test
are not tests (I think this is probably most common, though I have no data). When set totrue
, then_test.dart
anywhere will be considered a test.CodeLens would use this too, so you’d need to enable it to see codeLens for tests outside of
./test
.If it seems like many people are hitting this and unaware of the setting, we could do something basic like a regex over the file (if it ends with
_test.dart
) and if it looks like it might include tests, give the user a prompt asking which way they want (and persisting that setting so we don’t ask again).You could set the setting in User Settings (if you do this a lot, it’ll apply to all projects), but also if you have an open source/shared project doing this, you could commit it in
.vscode/settings.json
so that anyone opening that project will have it for that window.How does this sound?
I’m not sure what reason there is for having a file named
_test.dart
that is NOT a test file. It seems to me that it is a better assumption that ALL_test.dart
files are test files. It would be easier for someone who named a non-test file_test.dart
to rename that file than it will be for us to completely reorganize our project to relocate all test files to a/test
directory.