title: Data Driven Unit test on ClassInitialize
body: <p>I am trying to run some test with different values each time. For example: I have 3 methods: <code>methodA</code>, <code>methodB</code>, and <code>methodC</code>. I want to run each method twice with a different Index location. I have <code>TestInitialize</code> and <code>ClassInitialize</code> methods.</p>
  
  <ol>
  <li><p>I tried using <code>ClassInitialize</code> but I wasn't successful; I am getting compile time error because my test context is not static. </p>
  
  <pre><code>public TestContext TestContext
  {
     get { return testContextInstance; }
     set { testContextInstance = value; }
  }
  
  [DeploymentItem("UI.Framework.IntegrationTests\\ExpectedValues.xml")]
  [DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ExpectedValues.xml", "searchTerm2", DataAccessMethod.Sequential)]
  [ClassInitialize()]
  publicstaticvoid ClassInitialize(TestContext context)
  {        
     string indexPath = TestContext.DataRow[0].ToString();
     bool isSuccess1 = SearchApiTestsHelper.InitializeSearchEngine(indexPath, null);
     Assert.IsTrue(isSuccess1);
  }
  </code></pre>
  
  <p>I couldn't do this.</p></li>
  <li><p>I tried using <code>TestInitialize</code> but the data row was not being loaded, it was <code>null</code>.</p>
  
  <pre><code>[DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML",
              "|DataDirectory|\\ExpectedValues.xml", 
              "indices", 
              DataAccessMethod.Sequential),
  TestInitialize()]
  public void MyTestInitialize()
  {
      string indexPath = TestContext.DataRow[0].ToString();
      bool isSuccess1 = SearchApiTestsHelper.InitializeSearchEngine(indexPath, null);
      Assert.IsTrue(isSuccess1);
  }
  </code></pre></li>
  <li><p>I know I can set each method to run twice however, some methods require different data for validation. e.g <code>method2</code> still needs to run twice for each index location and for each run assert a set of expected values from the data source.</p>
  
  <pre><code>[DeploymentItem("UI.Framework.IntegrationTests\\ExpectedValues.xml")]
  [DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML",
              "|DataDirectory|\\ExpectedValues.xml", 
              "pb1", DataAccessMethod.Sequential),
   TestCategory("Integration")]
  [TestMethod]
  public void PhraseBoosting()
  {
      expectedVal = TestContext.DataRow[0].ToString();
  }
  </code></pre>
  
  <p>How can this be archived?</p></li>
  </ol>