title: How can I initialize TestContext property in another class?
body: <p>I am new to Selenium and I am trying to perform a data-driven test through CSV file. For this I am defining DataSource attribute in a class which contains test attributes. I am using MStest framework.</p>
  
  <pre><code>[TestClass]
  public class UnitTest1:BaseDriver
  {
  
      ExcelTest sd;
  
      private TestContext instance;
  
      public TestContext TestContext
      {
          set { instance = value; }
          get { return instance; }
      }
  
      public UnitTest1()
      {
  
          sd = new ExcelTest(_driver);              
      }
  
      [TestInitialize]
      public void Testinitialize()
      {
  
      }
  
      [TestMethod]
      [DeploymentItem("TestData.csv")]
      [DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", @"C:\Users\nidumukv\Documents\Visual Studio 2012\Projects\BMICalculator\BMICalculator\DataFiles\TestData.csv", "TestData#csv", DataAccessMethod.Sequential)]
      public void DDtest_usingCSV()
      {
          string feet = TestContext.DataRow["feet"].ToString();
          string inches = TestContext.DataRow["inches"].ToString();
          string weight = TestContext.DataRow["weight in pounds"].ToString();
          string BMI = TestContext.DataRow["BMI"].ToString();
  
  
          sd.TestUsingCSV(feet,inches,weight,BMI);
      }
  
      [TestCleanup]
      public void cleanup()
      { _driver.Quit(); }
  
  
  }
  </code></pre>
  
  <p>BaseDriver is a class I am using to store the actual webdriver. PageElements is a class in which I have declared all the web elements.</p>
  
  <p>I am trying to define the variables that are in 'DDtest_usingCSV' method in a seperate class so that the test does not become clumsy. But whenever I am defining another testcontext in another class I am getting a NullReferenceException. I have tried passing the property between classes. But I could not do it (I am still learning). </p>
  
  <p>Below is the class I am trying to initialize the TestContext</p>
  
  <pre><code> public class ExcelTest:PageElements
  {
      public IWebDriver _driver;
  
      public ExcelTest(IWebDriver driver):base(driver)
      {
          _driver = driver;
  
      }
  
  
      public void TestUsingCSV(string _feet,string _inches,string _weight,string _BMI)
      {
          feet.SendKeys(_feet);
          inches.SendKeys(_inches);
          weight.SendKeys(_weight);
          compute_btn.Click();
      }
  }
  </code></pre>
  
  <p>As I could not initialize the property, I am parameterizing that method in the test class file. </p>
  
  <p>And while declaring the TestContext property as mentioned below, why are we using "TestContext" as property name instead of instance?? </p>
  
  <pre><code>private TestContext instance;
  public TestContext TestContext
      {
          set { instance = value; }
          get { return instance; }
      }
  </code></pre>
  
  <p>At the time of reading values from excel, we are taking "TestContext" for accessing DataRow instead of "instance" . This question is bugging me whenever I look at it.</p>
  
  <pre><code>public void DDtest_usingCSV()
      {
          string feet = TestContext.DataRow["feet"].ToString();
          string inches = TestContext.DataRow["inches"].ToString();
          string weight = TestContext.DataRow["weight in pounds"].ToString();
          string BMI = TestContext.DataRow["BMI"].ToString();
  
  
          sd.TestUsingCSV(feet,inches,weight,BMI);
      }
  </code></pre>
  
  <p>Please don't mind the length of the question. I gave a detailed explanation on my problem. Any help can be appreciated. Thanks in advance.</p>