I want to compare the current test method name, but getting an exception that TestContext returns null.
public TestContext TestContext { get; set; }
private void SetTaxCode(Bene beneDetails)
{if (TestContext.TestName.Contains("NegativeTest"))
{SetBenecode(TestDataProvider.TestDataProvider.InValidBeneficiaryTaxCode);
}
else
SetBenecode(beneDetails.BeneficiaryTaxCode);
}
TestContext.TestName returns correct test name in the basic.cs, but I can't inherit basic.cs to the new class, how can I then use TestContext in different classes?
You could make your
TestContextproperty static. That way, you will be able to call it even without instantiating the basic.cs class.If basic.cs is not accessible to other classes, you could make a static class and put your
TestContextproperty there.