nunit.analyzers icon indicating copy to clipboard operation
nunit.analyzers copied to clipboard

Do Not Allow Any Assertions to be Used in TearDown

Open JasonBock opened this issue 8 years ago • 5 comments

Description

Based on discussion from here: https://github.com/nunit/docs/issues/149 If a method is marked with [TearDown], no assertion calls from the Assert class should be allowed.

Example

[TearDown]
public void TearDown()
{
  Assert.That(true, Is.True); // This line would be flagged.
}

Analyzer Message

"No methods from the Assert class may be used in a [TearDown] method"

Default Severity Level

Error

Code Fixes

none

JasonBock avatar Dec 16 '16 23:12 JasonBock

@JasonBock These seem like useful issues and they have crossreferenced activity. Would it bother you if we kept them open longer?

jnm2 avatar May 10 '20 15:05 jnm2

I was thinking the same. If you prefer to have a "clean slate" wrt. open NUnit issues you have created, then I can also create a new issue a replacement for this (and similar for the other two issues)

mikkelbu avatar May 10 '20 17:05 mikkelbu

You can re-open them if you like.

JasonBock avatar May 10 '20 18:05 JasonBock

Should the same analyser warn against use of Assume?

andrewimcclement avatar Aug 04 '23 00:08 andrewimcclement

Should the same analyser warn against use of Assume?

Yes, I would say so.

manfred-brands avatar Aug 04 '23 10:08 manfred-brands