Can't get 100% code coverage
Thanks.
protected overridevoid Dispose(bool disposing){if (disposing && (components !=null)) { components.Dispose(); } base.Dispose(disposing);} |
Thanks.
protected overridevoid Dispose(bool disposing){if (disposing && (components !=null)) { components.Dispose(); } base.Dispose(disposing);} |
Kunjal Karamshi wrote:
This could simply be a case of short-cut evaluation occuring when either one of the conditions is false.
Are you sure both expressions are true? The && operator only evaluates the second operand if necessary (if the first operand evaluates to true). In your code:
if (disposing && (components != null)) { //... }
If the first operand to && (disposing), evaluates to false, the second operand (components != null) will never be evaluated.
-E
Ernst Kuschke wrote:
Are you sure both expressions are true? The && operator only evaluates the second operand if necessary (if the first operand evaluates to true). In your code:
if (disposing && (components != null)) { //... }
If the first operand to && (disposing), evaluates to false, the second operand (components != null) will never be evaluated.
-E
The original poster said that the only line that wasn't marked as fully covered was that line which means that the lines inside the if were marked as fully covered. If this is true then the if statement would have had to have evaluated as true.... which means it should have full coverage.
I have also come across this numerous times. The only way to solve it is to put an & instead of an &&... I assume that the code coverage behaviour is like this because not all combinations of the && failing are being tested... In your example above the if could fail if the disposing is false or if components is equal to null... now if the unit tests (or running of the app with code coverage profiling turned on) only checks when disposing is false then the combination of disposing being true and components being false is not checked..... maybe that is why the code coverage is coming up as partial.... either way... it's not clear from the documentation and it's a bit misleading.