Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the Flutter test file search pattern from "_test"

I'd like flutter_test to find test files without the "_test" suffix. Where can I configure this pattern?

For python with pytest for instance, you'd change this setting in pytest.ini:

testpaths =
    tests
python_files = *.py

What's the Dart way of doing this?

like image 466
Jasper van den Bosch Avatar asked Oct 25 '25 16:10

Jasper van den Bosch


1 Answers

I have gone through your question in-depth and I found these things.

  1. I checked the test package and dig deep into the source code to see how they were actually doing the checking for _test.dart files. And I found out that in the pubspec.yaml, they have one dependency called glob (link) which I think they used to filter the files. I went through their code and found these particular lines for it:

enter image description here

Link to this page

I tried to fork the repository and then change the type there but it was still showing the same test files as before. So I tried a different approach.

  1. I tried to look into the VS Code plugin for test to see if I can change the type there but I couldn't found the exact module in which there defining the path. In VS-Code, we have an option in settings.json to search the test files outside of the test folder by this line.

"dart.allowTestsOutsideTestFolder": true

But there weren't any concrete options to change the test file search pattern for it. So my conclusion is if we were able to change the search pattern then we have to change in so many places which could also break some things. Therefore I would suggest to stick to the convention of it.

like image 157
Cavin Macwan Avatar answered Oct 28 '25 05:10

Cavin Macwan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!