How to Run Go Tests with Coverage Percentage
·
146 words
·
1 minute read
Go has a brilliant built in testing package, which although it is quite raw, it is very powerful. It also has the ability to show the test coverage as a percentage of the code base. Which is very useful to get perspective of a project and to know perhaps which areas need improvement.
You can see the test coverage by using the -coverprofile
parameter on the test command.
|
|
This is great, but even better is being able to visualise the test coverage. You can see which code is run during testing and which code is not by loading the cover profile in a browser. To do this, use this command:
|
|
Which will produce something like this (although I’ve cropped it down):