What is a CI?

For all of you who haven’t yet used a CI and are scratching your heads over what it is, here’s a quick intro from the official Travis CI website:

A CI supports your development process by automatically building and testing code changes, providing immediate feedback on the success of the change. Travis CI can also automate other parts of your development process by managing deployments and notifications.

Long story short, the CI we’re setting up is going to build and run all our test cases every time we commit our code. This frequent running of tests helps in building healthier software.

Registering for Travis CI

For our app we’ll be using Travis CI. It’s easy to integrate and has tons of options in terms of customizing the build script. We’ll be following this quick start guide to get started.

First up you need to go to travis-ci.com and Sign up with GitHub.

Accept the Authorization of Travis CI. You’ll be redirected to GitHub.

Click the green Activate button, and select the repositories you want to use with Travis CI.

Create Travis Configuration

Next step would be to write the configuration for the app. Right click on project root directory and create the following .travis.yml config file.

Let’s take a look at all the options in the configuration one by one:

language : sets up the environment for the specified language. Dart isn’t officially supported by Travis but there’s a community supported version available.

: sets up the environment for the specified language. Dart isn’t officially supported by Travis but there’s a community supported version available. dist : specifies the Ubuntu base version which we’re using. In my case Its Ubuntu 18.04 Bionic.

: specifies the Ubuntu base version which we’re using. In my case Its Ubuntu 18.04 Bionic. addons : Lets us specify any additional packages to be installed at runtime.

: Lets us specify any additional packages to be installed at runtime. install : We’re setting up the flutter build environment here and also running flutter doctor to verify the installation.

: We’re setting up the flutter build environment here and also running flutter doctor to verify the installation. script : This is the section where the tests are run using flutter test

: This is the section where the tests are run using cache : This specifies the directory where dart will cache its packages.

That’s all for the configuration.

Now commit and push your code to Github and Travis should install flutter and run the tests for you. But wait a second…

We have setup the CI but we haven’t cleaned up our main.dart test yet. Open up the widget_test.dart file and replace the existing test with the following. Also remove the unused material.dart import from the top of the test class.

This is a simple UI test for checking that the ‘Hello World!’ text is shown just once to the user. Do not panic if you don’t understand the test code you just wrote, we’ll discuss flutter tests in detail in coming days. Commit and push your code and this time the tests should pass !

Now that we have the CI setup, we will start working on the actual app from day 3.

Code Changes

#2 Added Travis CI

How Can You Contribute?

Open issues with suggestion of better approaches or ideas for the app.

Connect with me on Twitter or Linkedin or Instagram.

Star the Github repository.

Share the series on Twitter.

Follow me on Github.

Posts In This Series

Show Your Support

Press the clap button below if you liked reading this post. The more you clap the more it motivates me to write better!