How to get the unit test method name at runtime from within the unit test?

后端 未结 5 1722
栀梦
栀梦 2020-12-28 14:57

How to get the unit test name from the within unit test?

I have the below method inside a BaseTestFixture Class:

public string GetCallerMethodName()
         


        
5条回答
  •  悲哀的现实
    2020-12-28 15:21

    When using Visual Studio to run your tests if you add a TestContext property in your test class you can get this information easily.

    [TestClass]
    public class MyTestClass
    {
        public TestContext TestContext { get; set; }
    
        [TestInitialize]
        public void setup()
        {
            logger.Info(" SETUP " + TestContext.TestName);
            // .... //
        }
    }
    

提交回复
热议问题