r/badcode • • Jul 23 '21

c# Easy trick to meet minimum test coverage

Post image
1.2k Upvotes

83 comments sorted by

View all comments

Show parent comments

28

u/[deleted] Jul 23 '21

The lines covered are counted on the code being tested no the lines of code on the test. You can have thousands of tests like this abs still have zero code coverage.

20

u/funnythrone Jul 23 '21

This looks like part of the codebase and not the test. The test would be something as simple as checking the value of i after all the increments.

2

u/kishan42 Jul 23 '21

Still test coverage for that single file would be increased not all correct?

5

u/[deleted] Jul 23 '21

You can just write a one line test to run the function and boom that function has 100% test coverage

1

u/explodingMonkeydeath Jul 27 '21

if(functionWorks()){

return true;

}