A fork of ExCoveralls focusing on the 100% coverage use-case.
Shooting for 100% coverage is usually criticized as unnecessary and unproductive, and we tend to agree with that sentiment. But as far as measuring code coverage in percentage points goes, 100% is the only reasonable target: any other percent-based target flaps around when SLOCs are added or removed.
Instead of shooting for a hard "we must get 100% coverage" rule, Chaps recommends that you use ignores judiciously to avoid spending unnecessary time trying to increase coverage, but still set the target coverage percentage at 100%. This workflow sets a default "you must cover or ignore these lines" mantra which forces code authors to be explicit.
This workflow also allows one to setup automated CI checks to fail when the coverage is less than 100%, obviating the need to upload the coverage report to an external service like coveralls.
- Add the dependency to your
mix.exs
deps/0
function - Set the
test_coverage
tool in theproject/0
function - Set the
preferred_cli_env
to test for any tasks you intend to use
# mix.exs
def project do
[
app: :my_app,
version: "0.0.1",
elixir: "~> 1.6",
deps: deps(),
test_coverage: [tool: Chaps], #2
preferred_cli_env: [ #3
chaps: :test,
"chaps.html": :test
],
# ..
]
end
defp deps do
[
{:chaps, "~> 0.1", only: :test} #1
]
end
Run mix chaps
to run the test suite and show coverage. The output format
can be controlled by calling mix chaps.<output format>
instead, where
<output format>
can be any of
html
: an HTML based report showing coverage on source codedetail
: a terminal based output showing coverage on source codejson
,xml
, orlcov
: a JSON/XML/LCOV based data structure representing SLOCs
Chaps is configured in config/test.exs
like so
config :chaps,
coverage_options: [
treat_no_relevant_lines_as_covered: true
]
For the full schema, see the documentation of the Chaps.Settings
module.
Ignores in chaps are just about the same as they are in ExCoveralls:
# this piece of code is so hard to get meaningful coverage on that it's
# not worth our time, let's skip it
# chaps-ignore-start
def really_hard_to_get_coverage(args) do
# ..
end
# chaps-ignore-stop
- Coverage is truncated to the tenths place instead of rounded
- this enforces that for even very large projects, 100% coverage means all SLOCs are covered, not just approximately all SLOCs
- Tasks and dependencies for uploading coverage reports have been removed
- the
:hackney
dependency has been removed
- the
- Configuration is done in
config/test.exs
instead of a JSON file- the
:jason
dependency is optional and is only used if runningmix chaps.json
- the
This repository is a fork of
parroty/excoveralls
. Almost
all source code originates from the original repository. See the LICENSE
file for attribution information.