MoveNext() method not covered by unit testing?

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

Hi all,

I have writen a class which implements IEnumerable<T>. I have used
"yield return" to implement this, as follows:

public IEnumerator<int> GetEnumerator()
{
foreach (int i in items)
{
yield return item;
}
}

Now, I have written unit tests to cover this, but can't seem to get
coverage of an auto-generated MoveNext() method of the Enumerator. The
coverage window shows the following:

MyClass`2.<GetEnumerator>d__0 3 21.43 % 11 78.57 %
MoveNext() 3 21.43 % 11 78.57 %

[Note I've changed names to protect the identity of innocent
classes! ;)]

....as you can see, three blocks of code are not being covered.
However, when I double click the uncovered code, all code is displayed
in green, suggesting that it has been covered. While I appreciate that
100% coverage is not possible and certainly shouldn't be the aim (80%
is a more realistic aim), it's really annoying me that I can't cover
this.

I already tried marking the GetEnumerator as
[System.Diagnostics.DebuggerHidden] and that made no difference.

Does anyone know how to solve this?

Thanks in advance,

Steve.
 
Steve said:
Hi all,

I have writen a class which implements IEnumerable<T>. I have used
"yield return" to implement this, as follows:

public IEnumerator<int> GetEnumerator()
{
foreach (int i in items)
{
yield return item;
}
}

Now, I have written unit tests to cover this, but can't seem to get
coverage of an auto-generated MoveNext() method of the Enumerator. The
coverage window shows the following:

MyClass`2.<GetEnumerator>d__0 3 21.43 % 11 78.57 %
MoveNext() 3 21.43 % 11 78.57 %

[Note I've changed names to protect the identity of innocent
classes! ;)]

...as you can see, three blocks of code are not being covered.
However, when I double click the uncovered code, all code is displayed
in green, suggesting that it has been covered. While I appreciate that
100% coverage is not possible and certainly shouldn't be the aim (80%
is a more realistic aim), it's really annoying me that I can't cover
this.

I don't know for sure, but they are probably null reference and other
sanity checks. (As such they may not be testable, depending upon how
"insane" the state has to be for them to fail.)

Have you unit tested expected exceptions and exceptional situations,
such as calling MoveNext after it returns False?
 
Back
Top