Integrating Flutter with Coveralls

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. 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:
  - linux
sudo: false
addons:
  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-droid
before_script:
  - git clone https://github.com/flutter/flutter.git -b alpha --depth 1
  - ./flutter/bin/flutter doctor
script:
  - ./flutter/bin/flutter test test/unit_tests/* test/widget_tests/*
cache:
  directories:
    - $HOME/.pub-cache

Adding project to Coveralls

In order to add 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:
  - linux
sudo: false
addons:
  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-droid
before_script:
  - git clone https://github.com/flutter/flutter.git -b alpha --depth 1
  - ./flutter/bin/flutter doctor
  - gem install coveralls-lcov
script:
  - ./flutter/bin/flutter test --coverage test/unit_tests/* test/widget_tests/*
after_success:
  - coveralls-lcov coverage/lcov.info
cache:
  directories:
    - $HOME/.pub-cache

Profit

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 Coverage Status) 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. 🙂

Full example is available here.

If you have any questions, feel free to leave a comment 🙂

Leave a Reply

Your email address will not be published.