testfx icon indicating copy to clipboard operation
testfx copied to clipboard

How to get exception from test in TestCleanup?

Open VanKrock opened this issue 8 years ago • 2 comments

We can get UnitTestOutcome.Error from TestContext.CurrentTestOutcome in TestCleanup. How to get additional information about error? May be Exception? It's can be important for cleanup.

VanKrock avatar Oct 18 '17 00:10 VanKrock

@VanKrock : Currently there is no way to get additional information about the error. If we have enough asks for this feature, we will surely address this in our future releases.

jayaranigarg avatar Nov 01 '17 13:11 jayaranigarg

I'll pile onto this one. You seem to always have to give something up depending on which workaround you pursue.

There is a stackoverflow about this in which one answer suggests to subscribe to FirstChanceException, but being static, you're risking things getting screwed up when using parallel test execution.

That same stackoverflow has a MSTest V2 suggestion to use a TestMethodAttribute extension, which is better, but then as noted in another issue for V2, you don't have access to TestContext.

Can we not have our cake and eat it too? Please?

ghost avatar Feb 26 '20 17:02 ghost

+1 on this ask. We want to capture the exception in TestCleanup via the logging infra that is being used to capture the rest of the tracing. Currently our log files miss this last piece of information.

gaurav137 avatar Sep 29 '22 04:09 gaurav137