Overriding test result in TearDown

Bug #691455 reported by Josh
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
NUnit Framework
Triaged
Wishlist
Unassigned

Bug Description

[Issue now tracked at https://github.com/nunit/nunit-framework/issues/49]

NUnit version 2.5.7
Runner: Console and GUI

Feature Request:

I'd love to have the ability to override a test's result (e.g. Pass/Fail/Error) in the [TearDown] method along with the option to overwrite the error message.

Some more background:

I just started with a team that uses NUnit for running for automation testing. Given that NUnit is specifically built for unit testing, I've been surprised just how well it meets our needs. The only hangup I currently have is that we have certain classes of errors that only occur on threads other than the main thread. Without going into details, it's basically impossible for us respond to these errors on the main thread without adding code everywhere to poll if any of these errors have occurred, and if so, Assert.Fail(). Without detecting the errors at all, our code ends up asserting or throwing an exception for something else on the main thread which just ends up obfuscating the real problem in the resulting TestResult.xml file.

I understand why NUnit doesn't pick up assertions/exceptions on different threads, but we could easily workaround this if we had the ability to override the test result and error message in the [TearDown] method. At that point we'd know if any of these errors had occurred and could signal the test as failing and give a more appropriate message.

Tags: feature github
Revision history for this message
Charlie Poole (charlie.poole) wrote :

I'm attempting to determine just what's required for this feature.

Right now you have the ability to do an Assert in the teardown method with an error reported if it fails. What is lacking for this to satisfy you?

Changed in nunitv2:
status: New → Incomplete
Revision history for this message
Josh (ikirutemp) wrote :

Hey Charlie, thanks for taking the time to respond! I'm ashamed to admit that I somehow overlooked the obvious solution of throwing an assert into the TearDown method. I can confirm that it works just fine. Thanks again!

Revision history for this message
Josh (ikirutemp) wrote :

Spoke a little too soon. Asserting in the TearDown method is less than ideal. The assert will append its failure message to whatever errors/asserts were encountered in the SetUp or Test method when what I really want to do is replace the failure message entirely.

Revision history for this message
Charlie Poole (charlie.poole) wrote :

The TestContext in NUnit 2.x is read-only, so I'm re-targeting this bug to 3.0.

Changed in nunitv2:
status: Incomplete → New
affects: nunitv2 → nunit-3.0
Changed in nunit-3.0:
status: New → Triaged
importance: Undecided → Wishlist
description: updated
tags: added: github
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.