Hello @Eike ,
Thank you for taking time to post this issue in Microsoft Q&A forum.
This issue is related to the understanding of “Code Coverage (Blocks)”. Actually, a block is a piece of code with exactly one entry and exit point, and a line of code can contain more than one code block.
For detailed explanation, you can refer to this document: Report in blocks or lines:
“Code coverage is counted in blocks. A block is a piece of code with exactly one entry and exit point. If the program’s control flow passes through a block during a test run, that block is counted as covered. The number of times the block is used has no effect on the result.”
“A line of code can contain more than one code block. If this is the case, and the test run exercises all the code blocks in the line, it is counted as one line. If some but not all code blocks in the line are exercised, it is counted as a partial line.”
If you do some tests, you will find that when you call to test the ToString()
method in your unit test project, the Code Coverage Coloring feature will color all covered code lines in ChannelGroup
class, and if you don't unit test the ToString()
method, the Code Coverage Coloring feature will color all not covered code lines in ChannelGroup
class.
Some sample unit test screenshots based on your code snippets:
So actually these methods such as ChannelGroup()
number{ get; set;}
name{get;set;}
are used too.
I will recommend you change to use the “Code Coverage (Lines)”, as “Code Coverage (Lines)” is more close to the size of the fragments that you see in the source code.
Right-click in Code Coverage Results
window > select Add/Remove columns…
> check the Covered (Lines)
and Not Covered (Lines)
checkbox.
Best Regards,
Tianyu
- If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.