Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>For single initialization point you should use class marked with <a href="http://www.nunit.org/index.php?p=setupFixture&amp;r=2.4" rel="nofollow"><code>[SetUpFixture]</code></a> attribute and method marked with <code>[SetUp]</code>, for example:</p> <pre><code>[SetUpFixture] public class TestsInitializer { [SetUp] public void InitializeLogger() { LoggingFacility.InitLogger(); } } </code></pre> <p>Now, this method (<code>[SetUp] InitializeLogger</code>) will run <em>before any test</em> is run, same as one marked with <code>[TearDown]</code> will run once all tests are run. But here's the catch - what does <strong><em>any</em></strong> and <strong><em>all</em></strong> mean in this context? Tests from classes <strong>declared in the same namespace as class marked with <code>[SetUpFixture]</code></strong>. </p> <p>For example, assuming hierarchy like this:</p> <pre><code>- Tests --- Business ----- TestsInitializer.cs // SetUpFixture class ----- FirstBusinessTests.cs ----- SecondBusinesTests.cs --- ComplexLogic ----- VeryComplexLogicTests.cs </code></pre> <p><code>First</code> and <code>SecondBusinessTests</code> will run <strong>after</strong> <code>SetUp</code> from <code>TestsInitializer</code>, however <code>VeryComplexLogicTests</code> might run in random order.</p> <p>According to <a href="http://www.nunit.org/index.php?p=setupFixture&amp;r=2.4" rel="nofollow">linked documentation</a>, if you declare <code>SetUpFixture</code> class outside of any namespace, setup and teardown will apply for entire assembly:</p> <blockquote> <p>Only one SetUpFixture should be created in a given namespace. A SetUpFixture outside of any namespace provides SetUp and TearDown for the entire assembly.</p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload