Conditionally disabling NUnit?

Is there a way to make conditional TearDown in NUnit?

I have a TestFixture in which I need to run the cleanup code in just a few tests, and I really don't want to:

  • Run the TearDown method for each test.
  • Create a private helper method and call it from tests that need to be cleaned if I can avoid it.
+3
source share
2 answers

Unfortunately no.

Can you do the cleanup in [TestFixtureTearDown] so that after all tests are completed? I think it depends on whether to clean before the next test.

, , /TextFixture , . TearDown, .

Edit: , , , , , , , NUnit - , , . . , , , -

+2

TearDown :

[TearDown]
public virtual void TearDown()
{
  // Tear down things here
}

, , :

[TearDown]
public override void TearDown()
{
  // By not calling base.TearDown() here you avoid tearing down
}
0

Source: https://habr.com/ru/post/1713847/


All Articles