title: Constructor for Unit-Test running twice
body: <p>I have some test-code that is initializing some members which should be done just once at the beginning. This is why I used the constructor for that:</p>
  
  <pre><code>[TestFixture]
  public class MyTestClass
  {
      private readonly IUnitTestGeometryProvider m_GeometryProvider;
  
  
      public MyTestClass()
      {
          // do some heavy init-op
      }
  
      private IEnumerable&lt;TestCaseData&gt; TestCases()
      {
          yield return new TestCaseData(this.m_GeometryProvider.GetPolyline())
              .Throws(typeof(ArgumentException));
      }
  
      [TestCaseSource("TestCases")]
      public double Check_GetReducedArea_For_Invalid_Arguments(IGeometry theGeom)
      {
          return theGeom.GetReducedArea();
      }
  }
  </code></pre>
  
  <p>I know of the convention to use the <code>FixtureSetup</code>-attribute for initializing tests, e.g. from <a href="https://stackoverflow.com/questions/212718/when-do-i-use-the-testfixturesetup-attribute-instead-of-a-default-constructor">this question on SO</a>. However I noticed that the method <code>TestCases</code> is executed before the method marked with that attribute so I run into an <code>NullReferenceException</code> when evaluating the different testcases as the <code>m_GeometryProvider</code> is <code>null</code> at this time. </p>
  
  <p>So I debugged my code and set a breakpoint into the constructor. I noticed, that it is executed twice before any test has even been run. I assumed every testcase having its own instance of the <code>MyTestClass</code>, but as I have three different testcases and the constructor running twice this doesn't explain it. </p>
  
  <p>As the initialization is heavy I´d like to execute it just once. Is there a way to guarantee this? I´d like to avoid a <code>static</code> member as it often attracts colleagues to heavily use other <code>static</code> members just because there already is one. Furthermore I´d consider the test-init to be specific for one instance of my <code>MyTestClass</code> instead of the class itself - assuming there´s just one however.</p>
  
  <p>I'm using NUnit 2.5.10.</p>