Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - MoveNext() method not covered by unit testing?

Reply
 
Old 01-15-2009   #1 (permalink)
Steve


 
 

MoveNext() method not covered by unit testing?

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.

My System SpecsSystem Spec
Old 01-18-2009   #2 (permalink)
Mark Hurd


 
 

Re: MoveNext() method not covered by unit testing?

"Steve" <steve_barker333@xxxxxx> wrote in message
news:a11d8af9-98e0-47ca-b618-461a5f573875@xxxxxx
Quote:

> 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.)

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
"appRoot" Error When Unit Testing in TFS 2008 .NET General
Method invocation failed because [System.String] doesn't contain a method PowerShell
Unit Testing - The Merit of Writing Tests First is Questioned .NET General
Embedded testing method in scripts? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46