Tests code coverage in Visual Studio Code with C# and .Net Core
While writing tests for you code goes without saying, there is much to be said about code coverage of tests. How much of your code is actually covered by these tens of tests you just wrote? If you work in a TDD approach most probably you don't have such "mundane" questions. Of course you code is 100% covered. You did make sure every test failed before you added that line in your code to make it pass... and that conditional statement... or did you? While purists would argue there is no chance of no coverage I beg to differ. Let alone if you write your tests after the code is written... After such and such years and experience in the industry when we are nearing deadlines some things are thrown out the window. They shouldn't but they are. TL;DR tools help with coverage. In this case .Net Core Test Explorer with coverlet and Coverage Gutters.
Photo by Startup Stock Photos from Pexels |
Coverlet to the rescue
As I blogged a while ago I have made myself a warm and cozy development environment for Visual Studio Code. One thing that popped to mind was tests code coverage. How can I see the coverage of my tests before they reach the CI pipeline? After a surprising brief search online I discovered a dotnet core CLI tool called coverlet. One can use this tool to create a coverage file and feed that file to a coverage reporter or even in some of the CI tools out there. The tool mainly produces common formats for code coverage reporters. All one needs to do is install the coverlet tool and install a Nuget package to one's test project. Fortunately the tool's Github page has detailed installation and usage information.
.Net Core Test Explorer
So far so good. One can produce a textual representation of the coverage by running a command line tool. We are however developers and as such inherently lazy. I want the coverage to be updated every time I run my updated tests via the very very neat .Net Core Test Explorer extension for Visual Studio Code.
This extension discovers, runs all tests or single tests for debug and... test... via Code Lens as well as provide feedback on whether a single test has passed failed or is being skipped. One of its very useful features is the ability to feed the dotnet core test runner with arguments. Since we have coverlet installed we can now instruct the test runner to create the coverage (i.e. call coverlet), control the coverage file format and output location.
Part of the .Net Core Test Explore settings |
Coverage Gutters
This handy language agnostic extension will take coverage files in lcov format and paint the gutter next to the covered code in green orange or red at the hit of a keystroke. One side effect here is that that once the gutter is overlayed with the coverage one cannot set or remove breakpoints. There is, however, a workaround to this. Show the coverage inline... which actually is way better.
Part of the Coverage Gutters settings |
The reason why this is handy is because in conditional statements where more than one condition is tested, it actually shows the condition missed by the test. Green color is for covered, orange for partially covered and red for not covered at all.
Coverage Gutters example |
One caveat with this extension is that on Windows the "turn off coverage" keyboard shortcut does not work and cannot be set to the proposed combination. I opened in issue in Github and let the developer know. Unfortunately apart from setting a different keyboard shortcut there isn't anything else to do. I set mine to ctrl+shift+backspace.
I whipped up some code to demonstrate how these three extensions work together to help with coverage. You can find the code here.
Let me know in the comments below if you have found any more useful extensions for vscode!
Let me know in the comments below if you have found any more useful extensions for vscode!
This tool can be used very productively in order to create a file that will fully meet all the requirements.
ReplyDeleteThank you for such a productive work and providing us with such a successfull project! Keep it up, sir! What else can we say?
ReplyDeleteGenerally I do not read article on blogs, but I wish to say that this write-up very compelled me to try and do so! Your writing style has been amazed me. Thanks, quite nice post.
ReplyDeleteBest Buy Geek Squad Appointment |
Geek Squad Appointment Scheduling |
Geek Squad Appointments At Best Buy |
Make An Appointment With The Geek Squad |
Thanks for sharing this blog, this blog is more useful to me.
ReplyDeletePHP Training in Bangalore
PHP Training in Chennai
PHP Classes in Bangalore
Best PHP Training Institute in Bangalore
AWS Training in Bangalore
Data Science Courses in Bangalore
DevOps Training in Bangalore
Spoken English Classes in Bangalore
DOT NET Training in Bangalore
Thanks for the informative article. This is one of the best resources I have found in quite some time.
ReplyDeleteDot Net Training in T Nagar
Dot Net training in Velachery
graphic design courses in porur
Python Training in Tambaram
Android Training in Anna Nagar
Spoken English Classes in Anna
Nagar
Software Testing Training in T Nagar
Python training in chennai
Android Training in OMR
Software testing training in Anna Nagar
Geek Squad Chat is a well-known tech service provider company in the world. Our experts offer support for all types of technical problems faced in computers, laptops and smartphones. They even provide solutions for home appliances, TV, smart wearable and home theatre. We help our customers in setup, installation, repair, uninstallation, replacement, damage and other issues. Our dedicated support team is always available at your service and assures you for the quick resolutions. Book geek squad chat today and get your device fixed without wasting much time.
ReplyDeletegeek squad chat |
geek squad chat |
geek squad chat |
geek squad chat |
share some more coding.it may help me lot...share lot...ur coding too good.
ReplyDeleteAngularJS training in chennai | AngularJS training in anna nagar | AngularJS training in omr | AngularJS training in porur | AngularJS training in tambaram | AngularJS training in velachery
http://globexdocuments.co//
ReplyDeletehttp://globexdocuments.co//
http://globexdocuments.co//
http://globexdocuments.co//
http://globexdocuments.co//
http://globexdocuments.co//
http://globexdocuments.co//
http://globexdocuments.co//
Learned a lot of new things in this post. Thanks for taking the time to share this blog..
ReplyDeletemethod overloading in python
python packages list
what is substring
python code for linear regression
java interview questions and answers for experienced
python operator overloading
Your article is very impressed to me and i really like your post and kindly update here.
ReplyDeleteOracle DBA Training in Chennai
oracle apps dba training in chennai
Oracle Training in Chennai
Pega Training in Chennai
Linux Training in Chennai
Tableau Training in Chennai
Power BI Training in Chennai
Spark Training in Chennai
Appium Training in Chennai
I agree with this blog and information
ReplyDeleteStock broker
A charming conversation is worth remark. I believe that you should distribute more on this topic, it probably won't be an untouchable issue yet for the most part individuals don't examine these issues. To the following! Kind respects!!
ReplyDeletebest interiors
Tbilisi | Tbilisi, Georgia, Tbilisi, Georgia, T-2021 - Vitanium Art
ReplyDeleteTbilisi is a titanium welding Georgian city that columbia titanium pants was built 사이트 추천 by the Georgian government. It has been named the city titanium undertaker of Tbilisi in 2021 dewalt titanium drill bit set by
Main Features of Microsoft Office 2007 Crack Full Version Free Download. Completely interactive user interface; Supports XML, PDF and XPS file formats.MS Office 2007 Crack
ReplyDeleteThis piece of content is really fruitful for me.
ReplyDeleteApollo tractor tyre price
We really appreciate what you do. My favourite blog
ReplyDeleteNative Instruments Massive
Thank you for taking the time and sharing this information with us. Ziyyara offers customized CBSE Board Home Tuition online, with experienced and certified tutors, providing personalized attention to each student.
ReplyDeleteFor more info contact +91-9654271931 or visit Online Tuition for CBSE Board
I really like your post. I found it very helpful. Please keep posting such kind of valuable post. Dive into our meticulously curated list of over 1000+ Classifieds Submission Sites.
ReplyDeletevisit Classified submission sites
Very awesome post! I really like that and very interesting content. Keep it up a good job. Ziyyara Edutech's AS Level online courses and tutoring are here to provide the support you need.
ReplyDeleteBook A Free Demo Today visit AS level courses
This extension discovers, runs all tests or single tests for debug and... test... via Code Lens as well as provide feedback on whether a single test has passed failed or is being skipped. Online Nursing assignment help is a beacon for aspiring healthcare professionals, offering vital guidance in complex medical scenarios and patient care strategies. Quality assistance bolsters understanding of medical concepts and enhances critical thinking skills crucial in healthcare practice. However, authenticity is paramount; reputable services prioritize accurate information and ethical standards. Embrace nursing assignment help as a tool for enriching learning experiences and ensuring excellence in patient care.
ReplyDelete