![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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. 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 Specs![]() |
![]() |
| 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 | |||