Understanding the MSTest TestContext

前端 未结 5 1376
一个人的身影
一个人的身影 2020-12-14 07:03

Using MSTest, I needed to obtain the name of the current test from within the [TestInitialize] method. You can get this from the TestContext.TestName

5条回答
  •  生来不讨喜
    2020-12-14 07:30

    Issue can be resolved like this:

    First define a static property:

        private static string _targetUrl;
    

    Then assing the value from runsetting file inside the ClassInitialize type of method, Use TestContext as an input parameter.

    [ClassInitialize]
        public static void Initialize(TestContext testContext)
        {
            _targetUrl = testContext.Properties["targetUrl"].ToString();           
        }
    

    Variable is initialized, ready to use it further.

提交回复
热议问题