How to reset global assertion failure information?

356 views
Skip to first unread message

Ralf Westphal

unread,
Jul 12, 2018, 3:53:34 AM7/12/18
to NUnit-Discuss
I'd like to use NUnit Assert-functions on their own. That's working in principle, but what I observe is that messages of failed assertions get accumulated.

The first failing assertion's exception message might say:

failing 1: Expected: 42
  But was:  0

But the second failing assertion's exception might then be:

failing 2: Multiple failures or warnings in test:
  1)   Expected: 42
  But was:  0

  2)   Expected: True
  But was:  False

The first assertion's failure message gets repeated.

That's not the behavior I'm looking for.

So far I figured this is due to failures being reported to the current global TestContext.

My question: I can I reset the global failure information before a group of Assert functions gets run?

Thx for any hint in advance!

-Ralf

Ralf Westphal

unread,
Jul 12, 2018, 4:01:50 AM7/12/18
to NUnit-Discuss
Found the solution myself:

I have to wrap the use of Assert-functions in its own TestExecutionContext:

using (new NUnit.Framework.Internal.TestExecutionContext.IsolatedContext()) {
    ...
}
Reply all
Reply to author
Forward
0 new messages