Understanding the MSTest TestContext

前端 未结 5 1378
一个人的身影
一个人的身影 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:35

    As [ClassInitialize] is only called at the beginning, the test name is TestMethod1. This is stale after the first test run.

    TestContext is set for every method, and thus has the current test name.

    Yes, it is a bit silly.

提交回复
热议问题