mercredi 18 novembre 2015

C# access properties of a Test Settings file runtime

I have a test project which uses MSTest. And I have a testsettings file and have a properties in that file. as below.

<?xml version="1.0" encoding="UTF-8"?>
<TestSettings name="local" id="77572268-dd99-4f8c-a660-f5c8c1eec977" 
              xmlns="http://ift.tt/1o0hquU">
  <Description>These are default test settings for a local test run.</Description>

  <Execution>
    <TestTypeSpecific>
      <UnitTestRunConfig testTypeId="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b">
        <AssemblyResolution>
          <TestDirectory useLoadContext="true" />
        </AssemblyResolution>
      </UnitTestRunConfig>
    </TestTypeSpecific>
    <AgentRule name="Execution Agents">
    </AgentRule>
  </Execution>
  <Properties >
    <Property name="AAA" value="val1"></Property>
    <Property name="BBB" value="val2"></Property>
  </Properties>
</TestSettings>

But how can I access these properties in testsettings file values by name in runtime. How can I do that?

This is what currently I'am trying..

   [ClassInitialize]
    public static void TestClassInitialize(TestContext context)
    {
        var sad = context.Properties["AAA"].ToString();
    }

And it gives following exception

An exception of type 'System.NullReferenceException' occurred in TestAutomation.dll but was not handled in user code

Additional information: Object reference not set to an instance of an object.

Aucun commentaire:

Enregistrer un commentaire