goofballLogic
goofballLogic

Reputation: 40549

NUnit tests: Is IDisposable guaranteed if a non-expected exception is thrown?

If I create an IDisposable during the TestFixtureSetup of an NUnit test, and the test throws an unanticipated exception (e.g. external resource fails), will the IDisposable's Dispose() get called?

Added>>
If not, does NUnit provide guaranteed execution of TestFixtureTearDown or somewhere else that can be used for cleanup?

Upvotes: 4

Views: 1201

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039318

No it won't be called. IDisposable is used for deterministic finalization usually used in conjunction with the using statement. You could call the Dispose method in the TestFixtureTearDown though.

Upvotes: 6

Related Questions