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

后端 未结 5 1724
栀梦
栀梦 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:08

    If you are using NUnit 2.5.7 / 2.6 you can use the TestContext class:

    [Test]
    public void ShouldRegisterThenVerifyEmailThenSignInSuccessfully()
    {
        string testMethodName = TestContext.CurrentContext.Test.Name;
    }
    

提交回复
热议问题