How can I exclude a particular file from test coverage analysis?
Asked Answered
I

2

5

I have a few files in my Elixir application that I'd like to exclude from the test coverage reporting. I'm not using any fancy coverage tools right now; (though I'm not closed to the possibility of using such tools) I'm just using mix test --cover right now.

How can I tell the coverage analysis tools that a given file should not be included in the coverage analysis?

Integrated answered 7/5, 2019 at 17:46 Comment(0)
B
6

Elixir v1.11 added :ignore_modules

From the v15 docs (with a more comprehensive explanation):

:ignore_modules - modules to ignore from generating reports and in summaries. It is a list of module names as atoms and regular expressions that are matched against the module names.

Here's an example:

  def project do
    [
      # ...
      test_coverage: [ignore_modules: [Exclude.This, Exclude.That, ~r/\.LiveView\./]]
    ]
  end
Brummell answered 14/7, 2021 at 13:48 Comment(0)
S
2

It's not possible to do directly in Elixir at the moment. There are two libs that I know of where you can exclude specific modules.

Coverex https://github.com/alfert/coverex

Excoveralls https://github.com/parroty/excoveralls.

Check them out to see if you like them. For more information on this subject check out these links.

https://elixirforum.com/t/code-coverage-tools-for-elixir/18102/2

https://elixirforum.com/t/add-ability-to-exclude-specific-functions-modules-files-from-test-coverage-reports/15743/1

Shanelleshaner answered 7/5, 2019 at 20:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.