Feature: Measure Coverage with bashcov
Description
I found that measuring coverage with bashcov is actually quite simple when combined with bats
and gives very helpful results.
Goal is to get a cobertura coverage report and integrate it with gitlab.
Implementation ideas
test:
scripts:
- |
#install ruby and bashcov dependencies
apk add ruby
gem install bashcov simplecov simplecov-cobertura
- |
# merge any existing .simplecov settings with setting the cobertura formatter
echo '
require 'simplecov'
require 'simplecov-cobertura'
SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
' >> ${CI_PROJECT_DIR}/.simplecov.tmp
mv .simplecov .simplecov.old
cat .simplecov.tmp .simplecov.old > .simplecov
- bashcov -- bats --report-formatter junit --output reports $BASH_BATS_OPTS $BASH_BATS_TESTS
artifacts:
reports:
coverage_report:
coverage_format: cobertura
path: coverage/coverage.xml
bashcov can also generate html results, but for my taste the integration inside of gitlab is just all we need.