Integrating Flutter with Coveralls
This post quickly presents snippet on how to integrate Flutter app with Coveralls, which will give you feedback on test coverage in your app. Let’s get to it!
Integrating with Travis
At first, we need to integrate our app with Travis. The best starting point would be Yegor Jbanov’s post on Testing Flutter app with Travis. I highly recommend reading it first.
In my case I had to specify two directories in which tests were placed (since otherwise flutter test only run unit tests), so my initial .travis.yml file looked like this:
os: - linuxsudo: falseaddons: apt: # Flutter depends on /usr/lib/x86_64-linux-gnu/libstdc++.so.6 version GLIBCXX_3.4.18 sources: - ubuntu-toolchain-r-test # if we don't specify this, the libstdc++6 we get is the wrong version packages: - libstdc++6 - fonts-droidbefore_script: - git clone https://github.com/flutter/flutter.git -b alpha --depth 1 - ./flutter/bin/flutter doctorscript: - ./flutter/bin/flutter test test/unit_tests/* test/widget_tests/*cache: directories: - $HOME/.pub-cacheAdding project to Coveralls
In order to add a project to Coveralls, all you need to do is Sign In with your GitHub account, go to Add Repos and pick repository you would like to integrate.
Then, when you go to Repos, you should see your project.
Updating .travis.yml
To properly invoke coveralls on Travis build you need to change .travis.yml file as shown:
os: - linuxsudo: falseaddons: apt: # Flutter depends on /usr/lib/x86_64-linux-gnu/libstdc++.so.6 version GLIBCXX_3.4.18 sources: - ubuntu-toolchain-r-test # if we don't specify this, the libstdc++6 we get is the wrong version packages: - libstdc++6 - fonts-droidbefore_script: - git clone https://github.com/flutter/flutter.git -b alpha --depth 1 - ./flutter/bin/flutter doctor - gem install coveralls-lcovscript: - ./flutter/bin/flutter test --coverage test/unit_tests/* test/widget_tests/*after_success: - coveralls-lcov coverage/lcov.infocache: directories: - $HOME/.pub-cacheProfit
And that’s it! Now after proper build on Travis, you will be able to see your test coverage.
What is more, you can add a badge (like this
) to your project’s readme so that everyone will know how well your app is tested. To do that, go to repo’s detail page on Coveralls, click EMBED above BADGE icon and copy code snippet you need. 🙂
The full example is available here.