Join the DZone community and get the full member experience.Join For Free
i am a big fan of code coverage. enough has been written about the need of the same. it helps raise confidence within development teams, solidifies the unit testing process and alleviates some risks that lurk when there is not a plethora of quality assurance resources. when this is coupled with good peer code review and inspection practices that come with say git pull requests or atlassian crucible , you can be certain to a good degree that the funtionality at least at the unit level is not brittle. even though it is metrics vs inspections, i find that investment in keeping a track of code coverage metrics is better than having fagan inspections or reading code line by line with the whole team sitting around a table while taking multiple coffee breaks.
based, unit tests are defined using
and we are run using
as the test runner. builds are deployed on
instead of teaspoon.
note that i am working with a sexy macbookpro. so if you are using a windows machine (bless your heart) the commands may not be that different. please feel free to add those as comments if you end up trying this on windows.
now, let us first walk through the steps you will need to get going locally.
2. teaspoon depends on istanbul for coverage. install it as:
npm install -g istanbul
3. edit the gemfile of your rails app and enable the phantomjs gem as :
group :development, :test do ... gem 'phantomjs' ... end
phantomjs is a headless webkit browser.
4. now run bundle install to make sure phantomjs is installed.
you may have to actually run teaspoon as well to make sure phantomjs is installed.
bundle exec teaspoon
5. edit teaspoon_env.rb and enable at least these lines in the coverage area:
#... config.use_coverage = nil config.coverage do |coverage| coverage.reports = ["html"] #which coverage reports istanbul should generate...
now, in order to test and generate a default configuration report locally, do:
bundle exec teaspoon --coverage=default
report is generated under
folder in <app_home> folder, by the name of the configuration you specified.
there you will find
, open it and viola!
now, to get the same effect going for circleci build (that is cloud baby!) you first have to tell the circleci environment that coverage is on. this is done through circle.yml
so edit that file and add these following line under dependencies / pre section. this will install istanbul as part of the ci build, if it has not been done on a higher level.
- npm install -g istanbul
also in test / post section, enable coverage and then copy the artifacts to the default circle artifacts location. note that this may be different for you. no point make this a
task as teaspoon tests (if well written) are execute very quickly. but note that copy should be done after the teaspoon tests have run. in other words, the commands are sequential.
- bundle exec teaspoon --coverage=default - cp -r ./coverage/default $circle_artifacts
run the build. when it has run successfully, check the artifacts tab and scroll down for
more configuration options and settings can be set in teaspoon_env.rb . you may check out the teaspoon gem site for more settings.
Opinions expressed by DZone contributors are their own.