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

Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
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
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36820 110
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54260 488
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
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
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49266 226
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44778 311
New

We're in Beta

About us Mission Statement