[TestInitialize] public void TestInitialize() { TestContext.Properties.Add("environment", "qa"); // Other test initialization code } [TestMethod] public void TestMethod1() { if (TestContext.Properties["environment"] != null) { var environment = TestContext.Properties["environment"].ToString(); // Do something with environment } // Test method code }
[ClassInitialize] public static void ClassInitialize(TestContext context) { context.Properties.Add("database", "test_db"); // Other test initialization code } [TestMethod] public void TestMethod2() { if (TestContext.Properties["database"] != null) { var database = TestContext.Properties["database"].ToString(); // Do something with database } // Test method code }In this example, the "database" property is added to the test context in the ClassInitialize method using the TestContext object passed as a parameter. It can be accessed in the TestMethod2 method to determine which database the test is using. Package library: Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions