Automatically run test suites and coverage reports for open-source grails projects using Travis CI and coveralls

05 / Jun / 2015 by Aseem Bansal 0 comments

Automated testing helps a lot in maintaining the quality of code. But setting up CI environments like Jenkins may seem like a hassle if you are working on small projects. Luckily for us there is a simple solution, at least for open-source projects hosted(or mirrorred) on github.

Travis CI is a service freely offered to make builds for projects hosted on github. A lot of projects are using it – Spock, Grails being two names which everyone in Groovy, Grails ecosystem would be aware of. There are many others which are using this service. Seeing this I decided to give it a try.

It’s simple to login into Travis using github account. Travis has a guide for setting up which I used. It mentions that you need a .travis.yml file. For getting started you can copy this travis file that I started with for my Grails project. Add this to my project repo root and push to github. If all goes well then you will have a badge showing the build status which looks something like this.

travis_badge

Not automatically but you will have to add to README.MD file manually. The code for this can also be copied from my README.MD file. Change username and repository name. Same is also available via travis.

Obviously that’s not the only thing that you get.  You get this also. Clicking on any of these builds let’s you see the complete output of build.

travis_build_history

The builds are triggered automatically when you commit.

But what about coverage reports? Hang on, I am getting to that.

You can use coveralls Grails plugin to send the coverage report to coveralls. Firstly go to coveralls and login via github. Turn on the button for your repository.  Then head to coveralls plugin github and add the dependencies  to BuildConfig.groovy file. After doing that change .travis.yml to the this one.

Now make a commit. Wait till build is completed on travis and then you get this on coveralls.

coveralls_coverage

Well you will be getting this after two commits as this is per commit basis coverage report. But we are no nitpicking here. We get trends per file basis also by clicking the build. But let’s not add another picture and let people see it for themselves.

And we also get another badge showing the coverage percentage.

badges

The badges are automatically updated as you keep on committing. There is email service also which I have not explored. Maybe someone can try that and let us know how good that works.

FOUND THIS USEFUL? SHARE IT

Leave a comment -