New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flutter test coverage will not report untested files #27997
Comments
i searched the same question on stack overflow: but none answer it. |
I have found a temporary workaround for this issue. If you create a "fileLoader_test.dart" file like this:
then "flutter test --coverage" will recognize all files specified in the "lib.dart" files. |
yep @BigBl4ckW0lf I got this, but i must import all files in my project. |
If a file is not reachable by the entrypoint that executes coverage, then because the VM has never loaded the library it doesn't return any coverage information for us. The tester process could walk the filesystem and insert the remaining file URIs into the coverage report - it's not clear that would always be meaningful information or the right thing to do. |
I'm using @BigBl4ckW0lf's idea but didn't want to manually add them in case I forget. I've got a CI step which creates the file before running the coverage using this script #!/bin/sh
file=test/coverage_helper_test.dart
echo "// Helper file to make coverage work for all dart files\n" > $file
echo "// ignore_for_file: unused_import" >> $file
find lib -name '*.dart' | cut -c4- | awk -v package=$1 '{printf "import '\''package:%s%s'\'';\n", package, $1}' >> $file
echo "\nvoid main(){}" >> $file Just call it with your package name as an argument and it'll generate a test including all dart files in the lib folder |
Here is a version which exclude .g.dart files #!/bin/sh
file=test/coverage_helper_test.dart
echo "// Helper file to make coverage work for all dart files\n" > $file
echo "// ignore_for_file: unused_import" >> $file
find lib -not -name '*.g.dart' -and -name '*.dart' | cut -c4- | awk -v package=$1 '{printf "import '\''package:%s%s'\'';\n", package, $1}' >> $file
echo "void main(){}" >> $file |
were do I have to add thuis |
any way to avoid part libraries? Or just ignore the warning? |
Hi, #!/bin/sh
file=test/coverage_helper_test.dart
printf "// Helper file to make coverage work for all dart files\n" > $file
printf "// **************************************************************************\n" >> $file
printf "// Because of this: https://github.com/flutter/flutter/issues/27997#issue-410722816\n" >> $file
printf "// DO NOT EDIT THIS FILE USE: sh scripts/import_files_coverage.sh YOUR_PACKAGE_NAME\n" >> $file
printf "// **************************************************************************\n" >> $file
printf "\n" >> $file
printf "// ignore_for_file: unused_import\n" >> $file
find lib -type f \( -iname "*.dart" ! -iname "*.g.dart" ! -iname "*.freezed.dart" ! -iname "generated_plugin_registrant.dart" \) | cut -c4- | awk -v package="$1" '{printf "import '\''package:%s%s'\'';\n", package, $1}' >> $file
printf "\nvoid main(){}" >> $file Don't forget to change YOUR_PACKAGE_NAME by your package. And you can also ignore this file on your .gitignore.
|
@vrnvorona do you found any way to avoid part libraries from |
Didn't try anything yet sadly, so no. |
Add a |
Basic CI pipeline with code linting, format checking and unit testing. An HTML code coverage report is generated as an artifact. To be noted: the test coverage does not cover untested files. An open issue exists in the flutter repo (see flutter/flutter#27997). Left as is for now. To be noted: the (private) firebase configuration files for cause commune and Thinkerview are missing in the CI. Disabled related lint rules for the linter to run successfully in CI. We could add these files as a private git submodule dependency (?).
Its been quite some time and yet there seems to be little progress here, @jonahwilliams anything particular that's blocking this issue? Is it slated to be fixed in the next dart release? |
To add to the workarounds previously provided, I wrote one up in dart that also gets rid of files with a Just replace the
|
Just came across this issue as well and I found there is also a flutter package that does the exact same thing: We added it as a dev dependency to our pubspec.yaml and just call |
Hi everyone I used a simple workaround on my side. In the // ignore: unused_import
import 'package:example/main.dart';
void main() {
// Fake test in order to make each file reachable by the coverage
} Every file used by the app will be scanned by the coverage tool. 🎉 Enjoy 🎉 |
Thanks for this. Just a note, if you're using Windows (boo hiss, I know!) you need to replace \ with / for the generated imports, e.g.:
|
I've used the approach suggested above in the comments and it's worked great for most of my use cases, however I was wondering if there was a way to perform this action (include untested files in the coverage calculation) when the package uses the |
I think the better approach is to really test the main. By default any new Flutter app already includes a Widget test for the counter app. The workaround I suggested can provide metrics about uncovered sources but a cleaner way to do should be to create a simple I am wondering if we should include this test by default in the |
I run the
flutter test --coverage
as followsand here are my project's files;
the generated
Icov.info
looks like this:why coverage didn't include the untested files?
i know how to show coverage by tools like
genHtml
locv-sumary
I just want to know how to generate the Locv.info that includes untested files in my projects
The text was updated successfully, but these errors were encountered: