Accessing Failure message or stack trace in TearDown

327 views
Skip to first unread message

Naresh

unread,
May 25, 2012, 4:07:54 AM5/25/12
to nunit-...@googlegroups.com
Hello,

Is there any way to access the test failure reason in TearDown.

I thought of using TestContext object, but it tells you only the status and state. It will not give any info on the failure reason.

Thanks,
Naresh

Charlie Poole

unread,
May 25, 2012, 10:45:50 AM5/25/12
to nunit-...@googlegroups.com
Hi Naresh,

It seems like a slippery slope to start giving the test too much info
about it's context. This may encourage very complex teardowns, which -
I think - would be undesireable.

I would be in favor of making full info about the test to a special
attribute (Action Attribute) to be applied to tests. My reasoning is
that when you are writing an ActionAttribute, you are creating a
simple extension to NUnit itself but when you are writing TearDown
code, you are in the world of the test and are subject to a certain
degree of sandboxing.

Charlie
> --
> You received this message because you are subscribed to the Google Groups
> "NUnit-Discuss" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/nunit-discuss/-/SCjVZ0TF60sJ.
> To post to this group, send email to nunit-...@googlegroups.com.
> To unsubscribe from this group, send email to
> nunit-discus...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/nunit-discuss?hl=en.

Naresh Thandu

unread,
May 25, 2012, 10:52:37 AM5/25/12
to nunit-...@googlegroups.com
Hello Charlie,

Thanks for your response. I agree with your point. 

Can you advise me from where I can get the complete test info. 

Thanks,
Naresh
--
Regards,
Naresh Thandu,
+91-9916710222

Charlie Poole

unread,
May 25, 2012, 11:00:17 AM5/25/12
to nunit-...@googlegroups.com
Hi Naresh,

I'm travelling without a development machine, so I can't check it out
myself. Look at the docs for ActionAttributes and see what is passed
to the before and after methods. If my memory is correct, it's just
the object you created for the test, which is no help in this
situation.

Instead, we could pass the internal Test object, which contains a
pointer to your created object and also all the other info you want to
get. Unfortunately, I think this would require implementation in NUnit
3.0.

Charlie

Naresh Thandu

unread,
May 25, 2012, 11:14:05 AM5/25/12
to nunit-...@googlegroups.com
Hello Charlie,

I looked into Action Attributes and as you said it is not useful in my scenario.

They take object of TestDetails type which gives some basic info about the test.

The other option, we are still using nunit 2.6. So I don't think I can go with that.

Thanks,
Naresh
Reply all
Reply to author
Forward
0 new messages