i-n-g-m-a-r

i-n-g-m-a-r

Phoenix improve test coverage

How to improve phoenix test coverage?

Source

$ mix test --cover
......
Generating cover results ...

Percentage | Module
-----------|--------------------------
     0.00% | DemoWeb.Layouts
     0.00% | DemoWeb.PageHTML
    16.67% | DemoWeb.CoreComponents
    25.00% | Demo.DataCase
    50.00% | Demo.Repo
    50.00% | DemoWeb.ErrorHTML
    75.00% | Demo.Application
    75.00% | DemoWeb.Router
    80.00% | DemoWeb.Telemetry
   100.00% | Demo
   100.00% | Demo.Mailer
   100.00% | DemoWeb
   100.00% | DemoWeb.ConnCase
   100.00% | DemoWeb.Endpoint
   100.00% | DemoWeb.ErrorJSON
   100.00% | DemoWeb.Gettext
   100.00% | DemoWeb.PageController
-----------|--------------------------
    27.41% | Total

Coverage test failed, threshold not met:

    Coverage:   27.41%
    Threshold:  90.00%

Generated HTML coverage results in "cover" directory

Most Liked

D4no0

D4no0

What do you mean, what about 100% coverage :joy: ?

BTW totally agree, this is definitely not the responsibility of the developer to test generated modules, even if they are theoretically now part of your application.

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Taking a bit of a step back, I wonder if there is perhaps gaps in how the test coverage is measured? If he’s got basic tests to render say the front page you’d expect that to run the DemoWeb.PageHTML and Layouts modules.

D4no0

D4no0

To be fair I don’t understand even to this day what this metric achieves, the fact that tests execute 100% of your code, doesn’t mean that the tests won’t miss a bug.

In the world of agile development, where we make software that evolves over time, having 100% coverage is like shooting yourself in the leg, a lot of effort to write tests, tests are brittle because they cover all implementation details, a lot of effort to change code and rewrite tests.

I even worked at a company where they implemented mutation testing, where it would be literally impossible to change a line of code without a couple of tests failing.

Last Post!

sodapopcan

sodapopcan

As @benwilson512 said, it’s odd that in a vanilla project that Layouts and PageHTML are not being covered as the generated PageControllerTest is definitely exercising these.

In terms of CoreComponents, you will start to see coverage through your controller and live views test as you start using them. Of course, just adding a <.button>hello</.button> to PageControllerTest will increase the coverage without asserting anything about it, so I take coverage with a grain of salt.

Where Next?

Popular in Questions Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
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
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

Other popular topics Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54921 245
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
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 49084 226
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
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
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement