Search code examples
opencover

How OpenCoverage coverage works - are classes without any tests counted?


I think I have a basic misunderstanding of the way OpenCover (or coverage in general) is working.

I think that classes without any tests are not counted in the coverage, which is very strange.

for example, if I have two classes (lets say of the same number of lines) and one is fully covered while the other has NO UT written, I expect to get 50% coverage, but I believe that I am getting 100%. This doesn't make sense to me.

So I have 2-3 questions:

  1. Should I expect classes without any UT to be counted in the coverage %?
  2. If so, how can I troubleshoot my issue? (should I look for something in the report? what exactly? is it possible that OpenCover ignores those classes for another reason?)
  3. If not, how does this make sense? if I start adding UT to a legacy project, the coverage will drop every time I add UT to a class that did not have one until now. there must be something that I am missing if this is the case.

Thank you for you help, Roy.


Solution

  • I suspect the assembly is not loaded and so it (and all the classes within it) are not seen by OpenCover.

    Simplest way is to add tests for at least one type in each assembly you wish to get coverage for.