Just came across the code coverage package. Seems like a very useful tool, so I’ve been prototyping with it a bit. Ran into a fairly common case that seems like it should work, so just verifying if I’m doing something wrong, or it’s a known issue I haven’t seen documented.
What I’m trying to do is check the code coverage on a generic C# class or method. But the generic method or class always has 0 coverage. Here’s some screenshots of an example I tried.
Test:
[TestFixture, SingleThreaded]
public class Tests
{
[Test]
public void Test()
{
Code code = new Code();
code.GetInt(5);
}
}
Coverage:
Any one has gotten it working with generics and has advice?
I have noticed the same issue and also wondered about abstract classes. It seems that only concrete classes and implementations can be detected by the coverage tool. At first glance this kind of makes sense because that is the code that actually runs, whereas the generic definition or abstract class is only a like template for the code that is produces from it. However, it would of course be a great feature to support this, because quite a lot of code is affected.
There are two parts to this issue. First one is that code coverage API is not handling generics well (issue tracker link posted previously). Coverage package was doing some work on top to handle generics and as a result it was working properly when using the package.
Earlier today we have released Code Coverage package 1.2.3 which fixes the generics issue. Coverage data for generic methods should be correct once again.