Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

100% code coverage, complaining about MoveNext()

I am trying to achieve 100% code coverage. However, somehow code coverage is complaining about some MoveNext() method that is not covered, however, there is no code path that's iterating an IEnumerable...

Code coverage result

Code snippet

Any ideas how to cover the MoveNext method? Where is the MoveNext() located?

like image 343
Identity Avatar asked Sep 19 '26 16:09

Identity


2 Answers

Honestly, and I'm speaking from experience of trying to attain and maintain 100% code coverage for a medium sized project with an average sized team where the code followed SOLID principles reasonably well, you should forget trying to achieve 100% code coverage.

Best practices suggest that, for good reason, a system with 70% coverage is pretty good, 80% very good, 90% exceptional. It sounds like you're in the high nineties, so you be proud, and not overly worry about that final piece which, by the sounds of it, isn't even testing your code base per se. Or to put it another way, would you rather hit that 100% holy grail or spend the time refactoring code to make future maintenance easier ?

When I tried maintaining 100% coverage I was new to C# and ended up writing unit tests to test the .Net framework's getters and setters - I thought I was really clever hitting 100% (for all of one week until someone in the team added a few lines of ultra-somple code) and then someone politely pointed out the stupidity of some of my tests - what a fool I felt.

I realise that my "answer" does not actually answer your question, and I started off this response as a comment, not an answer, but as I was writing I realised that my comments were so relevant that even without directly answering the question a mere comment was an insufficient explanation. I truly admire any attempt at 100% coverage, but don't get hung up on achieving it - "done is better than perfect".

Good luck nevertheless !

like image 178
Greg Trevellick Avatar answered Sep 22 '26 07:09

Greg Trevellick


What worked for me was to exclude the MoveNext() method in the .runsettings file for my solution:

        <Functions>
          <Exclude>
            <Function>.*MoveNext.*</Function>
          </Exclude>
        </Functions>

See this related Stack Overflow post.

like image 44
Tony S. Avatar answered Sep 22 '26 08:09

Tony S.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!