Code that is invoked when initializing static fields of classes is not considered covered by tests. Although there are cases where this makes sense, I'm not so sure it makes sense in general.
I have an AnonymousComparer class. It happens that the only place it is instantiated is to initialize a few static fields (representing different ways of ordering a particular type). I expected to see the anonymous comparer class as 'covered', because I was using its results as part of other tests. However, it isn't considered covered.
Perhaps a more serious issue, that is probably related, is that static fields seem to flip/flop between being marked as covered and being marked as not covered. But I haven't figured out exactly what triggers that yet.
[DebuggerStepThrough]
public sealed class AnonymousComparer<T> : IComparer<T> {
private readonly Func<T, T, int> _compare;
public AnonymousComparer(Func<T, T, int> compare) {
if (compare == null) throw new ArgumentNullException("compare");
this._compare = compare;
}
public int Compare(T x, T y) {
return _compare(x, y);
}
}