{"id":20727,"date":"2015-06-05T11:19:47","date_gmt":"2015-06-05T05:49:47","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=20727"},"modified":"2017-04-25T10:00:55","modified_gmt":"2017-04-25T04:30:55","slug":"automatically-run-test-suites-and-coverage-reports-for-open-source-grails-projects-using-travis-ci-and-coveralls","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/automatically-run-test-suites-and-coverage-reports-for-open-source-grails-projects-using-travis-ci-and-coveralls\/","title":{"rendered":"Automatically run test suites and coverage reports for open-source grails projects using Travis CI and coveralls"},"content":{"rendered":"<p>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.<\/p>\n<p><a title=\"Travis CI\" href=\"https:\/\/travis-ci.org\/\">Travis CI<\/a>\u00a0is a service freely offered to\u00a0make builds for projects hosted on github.\u00a0A lot of projects are using it &#8211; <a href=\"https:\/\/github.com\/spockframework\/spock\">Spock<\/a>, <a href=\"http:\/\/www.tothenew.com\/grails-application-development\">Grails<\/a>\u00a0being 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.<\/p>\n<p>It&#8217;s simple to login into Travis using github account.\u00a0Travis has a guide for <a href=\"http:\/\/docs.travis-ci.com\/user\/getting-started\/\">setting up<\/a>\u00a0which I used.\u00a0It mentions that you need a .travis.yml file.\u00a0For getting started you can copy this <a href=\"https:\/\/github.com\/anshbansal\/linksharing2\/blob\/8113007f3dc163e787aeb81b5f9c2a3991d150dd\/.travis.yml\">travis file<\/a>\u00a0that I\u00a0started with for my Grails project. Add\u00a0this 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.<\/p>\n<p><a href=\"\/blog\/wp-ttn-blog\/uploads\/2015\/06\/travis_badge.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-20731\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/06\/travis_badge.png\" alt=\"travis_badge\" width=\"820\" height=\"191\" \/><\/a><\/p>\n<p>Not automatically but you will have\u00a0to add to README.MD file manually.\u00a0The code for this can also be copied from my <a href=\"https:\/\/github.com\/anshbansal\/linksharing2\/edit\/master\/README.md\">README.MD<\/a> file. Change username and repository name. Same is also available via travis.<\/p>\n<p>Obviously that&#8217;s not the only thing that you get. \u00a0You get <a href=\"https:\/\/travis-ci.org\/anshbansal\/linksharing2\/builds\">this<\/a> also. Clicking on any of these builds let&#8217;s you see the complete output of build.<\/p>\n<p><a href=\"\/blog\/wp-ttn-blog\/uploads\/2015\/06\/travis_build_history.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-20732\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/06\/travis_build_history.png\" alt=\"travis_build_history\" width=\"1479\" height=\"849\" \/><\/a><\/p>\n<p>The builds are triggered automatically when you commit.<\/p>\n<p>But what about coverage reports? Hang on, I am getting to that.<\/p>\n<p>You can use coveralls Grails plugin to send the coverage report to <a href=\"https:\/\/coveralls.io\/\">coveralls<\/a>. Firstly go to coveralls and login via github. Turn on the button for your repository.\u00a0\u00a0Then\u00a0head to coveralls plugin\u00a0<a href=\"https:\/\/github.com\/agorapulse\/grails-coveralls\">github<\/a> and add the dependencies \u00a0to BuildConfig.groovy file. After doing that change .travis.yml to the <a href=\"https:\/\/github.com\/anshbansal\/linksharing2\/blob\/8ece6294211809b1070937b45e8740d496ac159f\/.travis.yml\">this one<\/a>.<\/p>\n<p>Now make a commit. Wait\u00a0till build is completed on travis and then you get\u00a0this on coveralls.<\/p>\n<p><a href=\"\/blog\/wp-ttn-blog\/uploads\/2015\/06\/coveralls_coverage.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-20733\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/06\/coveralls_coverage.png\" alt=\"coveralls_coverage\" width=\"1439\" height=\"442\" \/><\/a><\/p>\n<p>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&#8217;s\u00a0not add another picture and let people see it for <a href=\"https:\/\/coveralls.io\/r\/anshbansal\/linksharing2?branch=master\">themselves<\/a>.<\/p>\n<p>And we also get another badge showing the coverage percentage.<\/p>\n<p><a href=\"\/blog\/wp-ttn-blog\/uploads\/2015\/06\/badges.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-20735\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/06\/badges.png\" alt=\"badges\" width=\"852\" height=\"274\" \/><\/a><\/p>\n<p>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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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\u00a0is a service freely offered to\u00a0make builds [&hellip;]<\/p>\n","protected":false},"author":161,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":3},"categories":[1818,7],"tags":[1561,1847,503,4840,1846],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/20727"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/161"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=20727"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/20727\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=20727"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=20727"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=20727"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}