Code coverage is the process of doing analysis in C# unit test code to find out which block or statement of code is executed or not.
The basic code coverage criteria are
1. Function coverage
2. Statement coverage
3. Branch Coverage
There are so many tools available for this task
1. Visual Studio code coverage (Only in enterprise edition)
3. JetBrains dotCover
I had gone through the few important code coverage tool
1.Visual Studio code coverage (Only in enterprise edition)
>> In visual studio enterprise edition default code coverage tool will be there. Since i am not using the enterprise version, I did not do deep on analysis on this tool. If you are using the enterprise edition you can go through the below URL
2. NCover Code Coverage
>> Ncover is third party tool for visual studio.It is not the free tool. For this we have to download the software from given below URL
This tool is very straight forward to use. Firstly we have to install the tool then we will get the Ncover Menu in visual Studio.
Click on Ncover Code Coverage then you will get the Ncover Test Runner. It will load all the test case written in your application
Here i have written the test code like this
In the above test method, it will run only else condition so we are not testing the code of if condition. So if we will run the NCover tool it will show covered code as green and not covered code as red as given in above image.
It helps to find out the uncovered code in test application. This tool has also option to view the result on Desktop. It has also option to download the report in different format like html,Json and XML.