TearDown always throw TargetInvocationException.

34 views
Skip to first unread message

Kenneth Xu

unread,
Aug 9, 2009, 11:27:29 PM8/9/09
to nunit-...@googlegroups.com
Hi,

I noticed that the tear down always throw TargetInvocationException.
Which is the result of using reflection to invoke the tear down
methods. For example:

TearDown : System.Reflection.TargetInvocationException : Exception has
been thrown by the target of an invocation.
----> NUnit.Framework.AssertionException : Thread pool was not terminated.

Would it be better if the actual exception is reported instead of the
TargetInvocationException?

Thanks,
Kenneth

Charlie Poole

unread,
Aug 9, 2009, 11:47:43 PM8/9/09
to nunit-...@googlegroups.com
Hi Kenneth

Yes, it would. :-)

NUnit systematically removes any TargetInvocationExceptions
caused by its own use of reflection - as opposed to the
code in the test or the system under test. This could be
one we missed. Would you file a bug?

Charlie

Kenneth Xu

unread,
Aug 10, 2009, 1:22:44 PM8/10/09
to nunit-...@googlegroups.com
Hi Charlie,

Where should I file the bug, SourceForge or Lunchpad?

It turned out to be a simple fix:

-
tearDownMethods[index].Invoke(tearDownMethods[index].IsStatic ? null :
this.Fixture, new object[0]);
+ Reflect.InvokeMethod(tearDownMethods[index],
tearDownMethods[index].IsStatic ? null : this.Fixture);

Here I attached the patch, the test case was much more involved then
the fix because I didn't find one in the project. In the mean time,
the newly added test cases also discovered another problem. When
exception occurred in the SetUp, the FailureSite was reported as Test
instead of SetUp. I commented the assertion and added a TODO there.

Cheers,
Kenneth

teardownexception.diff

Charlie Poole

unread,
Aug 10, 2009, 1:40:38 PM8/10/09
to nunit-...@googlegroups.com
It's souceforge for 2.5 bugs - for another week anyway. :-)

Thanks for the patch. I'll release it in 2.5.2 today or
tomorrow.

Charlie

Kenneth Xu

unread,
Aug 10, 2009, 2:53:56 PM8/10/09
to nunit-...@googlegroups.com

Charlie Poole

unread,
Aug 10, 2009, 4:03:37 PM8/10/09
to nunit-...@googlegroups.com
Ah, I guess one was for 3.0. I misunderstood and deleted one of
them. Don't worry, however, because we'll pick up all bug fixes
since 2.5 for the 3.0 version.

Charlie

> -----Original Message-----
> From: nunit-...@googlegroups.com
> [mailto:nunit-...@googlegroups.com] On Behalf Of Kenneth Xu
> Sent: Monday, August 10, 2009 11:54 AM
> To: nunit-...@googlegroups.com
> Subject: [nunit-discuss] Re: TearDown always throw
> TargetInvocationException.
>
>

Kenneth Xu

unread,
Aug 10, 2009, 10:02:54 PM8/10/09
to nunit-...@googlegroups.com
Yeah, the other one was about "When exception occurred in the SetUp,
the FailureSite was set to Test instead of SetUp". Somehow the subject
was cut off.

Kenneth

Charlie Poole

unread,
Aug 10, 2009, 10:11:50 PM8/10/09
to nunit-...@googlegroups.com
Ah... OK, I reinstated it and changed the title. The 2.5.2
release is out, but we'll catch it for the next one.

Charlie

> -----Original Message-----
> From: nunit-...@googlegroups.com
> [mailto:nunit-...@googlegroups.com] On Behalf Of Kenneth Xu
> Sent: Monday, August 10, 2009 7:03 PM
> To: nunit-...@googlegroups.com
> Subject: [nunit-discuss] Re: TearDown always throw
> TargetInvocationException.
>
>
Reply all
Reply to author
Forward
0 new messages