i-n-g-m-a-r
Phoenix improve test coverage
How to improve phoenix test coverage?
$ 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
What do you mean, what about 100% coverage
?
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
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
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
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.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









