PC Review


Reply
Thread Tools Rate Thread

MoveNext() method not covered by unit testing?

 
 
Steve
Guest
Posts: n/a
 
      16th Jan 2009
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.
 
Reply With Quote
 
 
 
 
Mark Hurd
Guest
Posts: n/a
 
      19th Jan 2009
"Steve" <(E-Mail Removed)> wrote in message
news:a11d8af9-98e0-47ca-b618-(E-Mail Removed)...
> 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?

--
Regards,
Mark Hurd, B.Sc.(Ma.) (Hons.)

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Software Testing – Unit Testing With Typemock Isolator dove.jo Microsoft VC .NET 0 23rd Aug 2008 12:06 AM
Software Testing – Unit Testing - Free License for Open Source Projects spparrow.mo Microsoft Dot NET Framework Forms 0 22nd Aug 2008 07:10 PM
Software Testing – Unit Testing - Free open source license sparroww.mo Microsoft Dot NET 0 22nd Aug 2008 06:46 PM
Unit testing and performance load testing Curtis Justus Microsoft C# .NET 2 19th Jan 2005 03:59 PM
Re: ADO Record Set: MoveNext method failure StCyrM Microsoft Access VBA Modules 0 14th Jul 2004 03:34 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:11 PM.