mix test.coverage

Build report from exported test coverage.

When using --cover with the default coverage tool, the coverage tool supports an :export option to export the coverage results into a directory. This is useful when there are multiple test suites (such as in an umbrella app) or when a single test suite is partitioned across multiple runs when using the mix test --partitions N option.

Once multiple test runs are exported, this task can be used to generate an aggregated report.

Example: aggregating partitioned runs

If you partition your tests across multiple runs, you can unify the report as shown below:

MIX_TEST_PARTITION=1 mix test --partitions 2 --cover
MIX_TEST_PARTITION=2 mix test --partitions 2 --cover
mix test.coverage

This works because the --partitions option automatically exports the coverage results.

Example: aggregating coverage reports from all umbrella children

If you run mix test.coverage inside an umbrella, it will automatically gather exported cover results from all umbrella children - as long as the coverage results have been exported, like this:

# from the umbrella root
mix test --cover --export-coverage default
mix test.coverage

Of course, if you want to actually partition the tests, you can also do:

# from the umbrella root
MIX_TEST_PARTITION=1 mix test --partitions 2 --cover
MIX_TEST_PARTITION=2 mix test --partitions 2 --cover
mix test.coverage

On the other hand, if you want partitioned tests but per-app reports, you can do:

# from the umbrella root
MIX_TEST_PARTITION=1 mix test --partitions 2 --cover
MIX_TEST_PARTITION=2 mix test --partitions 2 --cover
mix cmd mix test.coverage

When running test.coverage from the umbrella root, it will use the :test_coverage configuration from the umbrella root.

Finally, note the coverage itself is not measured across the projects themselves. For example, if project B depends on A, and if there is code in A that is only executed from project B, those lines will not be marked as covered, which is important, as those projects should be developed and tested in isolation.

© 2012 Plataformatec
Licensed under the Apache License, Version 2.0.
https://hexdocs.pm/mix/1.11.2/Mix.Tasks.Test.Coverage.html