fireproofsocks

fireproofsocks

Test coverage for structs and mocks

I’m working on a umbrella app that relies on the built-in test coverage tools to generate reports, e.g

mix test --cover --export-coverage default
mix test.coverage

I’m noticing that modules that do nothing other than declare structs and mocked modules (mocked via mox) both show up as 0% coverage in the coverage report. For example:

defmodule Bar do
  defstruct [:a, :b, :c]
end
Mox.defmock(FooMock, for: Foo)

earn both modules an entry in the report, e.g.

Percentage | Module
-----------|--------------------------
     0.00% | Bar
     0.00% | FooMock
-----------|--------------------------
     0.00% | Total

Is the only way to ignore these types of modules from the final output to explicitly list them in the ignore_modules section, e.g.

def project do
[
    # ...
    test_coverage: [ignore_modules: [Bar, FooMock]]
]
end

There are reasons why we cannot currently use excoveralls or other tools for this (even though ExCoveralls doesn’t “mis-diagnose” these particular cases IIRC). Is there some other way to modify our report? Or is this report actually telling us something useful that I have overlooked?

Thanks for any insights!

First Post!

tjchambers

tjchambers

Did you ever get a response to this? Would be interested.

Last Post!

sodapopcan

sodapopcan

According to the docs, mix test.cover only covers executable lines of code. See here. It mentions:

Code in macros are also often executed at compilation time, and therefore may not be covered.

so that likely includes defstruct.

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New

Other popular topics Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement