Ashton Wiersdorf
Ashton Wiersdorf

Reputation: 2020

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

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?

Upvotes: 6

Views: 3238

Answers (2)

Roger Lipscombe
Roger Lipscombe

Reputation: 91925

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

Upvotes: 7

Fiv
Fiv

Reputation: 175

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

Upvotes: 2

Related Questions