title: How to properly make use of TestContext.Properties
body: <p>I need to access <code>TestContext.Properties</code> before a <code>TestMethod</code> so the test can receive the correct environment to test.</p>
  
  <hr>
  
  <p>The contents of my <code>test.runsettings</code>:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
    &lt;RunSettings&gt;
      &lt;TestRunParameters&gt;
        &lt;Parameter name="colegio" value="7" /&gt;
      &lt;/TestRunParameters&gt;
  </code></pre>
  
  <h2>      </h2>
  
  <p>As you can see, the file only contains one parameter, called <code>colegio (school)</code></p>
  
  <hr>
  
  <p>This are the contents of <code>TestBase.cs</code>:</p>
  
  <pre class="lang-cs prettyprint-override"><code>using Microsoft.VisualStudio.TestTools.UnitTesting;
  using InfraestructureSelenium.Helper;
  using System.Collections.Generic;
  using InfraestructureSelenium.Configuration.Enumerados;
  
  namespace TestSelenium
  {
      [DeploymentItem("chromedriver.exe")]
      [DeploymentItem("IEDriverServer.exe")]
      [DeploymentItem("phantomjs.exe")]
      [DeploymentItem("geckodriver.exe")]
      [TestClass]
      public class TestBase
      {
          protected TestBase()
          { }
  
          public TestBase(int id = (int)ColegioEnum.ColegioDemoMovilidad2_Supervisor)
          {
              DiccionarioCompartido = new Dictionary&lt;string, string&gt;();
              SeleniumHelper = new HelperSelenium(id, WebDriverSelector.ObtenerWebDriver());
          }
  
          public TestBase(HelperSelenium seleniumHelper, Dictionary&lt;string, string&gt; diccionarioCompartido = null)
          {
              SeleniumHelper = seleniumHelper;
          }
  
          public HelperSelenium SeleniumHelper { get; set; }
  
          public static Dictionary&lt;string, string&gt; DiccionarioCompartido { get; set; }
  
          public void CloseBrowser()
          {
              SeleniumHelper.Quit();
          }
  
          #region Configuración Test
  
          [TestInitialize]
          public void InitializeTest()
          {
  
          }
  
          [TestCleanup]
          public void TestCleanupTest()
          {
              SeleniumHelper.Quit();
          }
  
          #endregion
          }
      }
  </code></pre>
  
  <hr>
  
  <p>As you can see, <code>public TestBase(int id = (int)ColegioEnum.ColegioDemoMovilidad2_Supervisor)</code> receives an argument, which corresponds to the <code>colegio</code> environment I want to test. If no <code>colegio</code> is passed as an argument, the default one will be <code>ColegioEnum.ColegioDemoMovilidad2_Supervisor</code></p>
  
  <p>However, when I try to instantiate <code>TestContext</code>in a <code>TestClass</code>, like this:</p>
  
  <pre class="lang-cs prettyprint-override"><code>[TestClass]
      public class GenerarBoletinDeClase : TestBase
      {
          public TestContext TestContext { get; set; }
  
          private static TestContext _testContext;
  
          [TestInitialize]
          public static void SetupTests(TestContext testContext)
          {
              _testContext = testContext;
          }
  
          public GenerarBoletinDeClase() : base((int)TestContext.Properties["colegio"]) { }
  </code></pre>
  
  <p>The following error appears: <code>An object reference is required for the non-static field, method, or property</code></p>
  
  <p>Any help is appreciated as I've given this problem a lot of time and I couldn't progress any further.</p>