Get name of running test in Xunit

前端 未结 3 1767
予麋鹿
予麋鹿 2021-02-18 15:52

Using Xunit, how can I get the name of the currently running test?

  public class TestWithCommonSetupAndTearDown : IDisposable
  {
    public TestWithCommonSetup         


        
3条回答
  •  后悔当初
    2021-02-18 16:30

    See a similar question in Github where the answer/workaround is to use some injection and reflection i the constructor.

    public class Tests
      {
      public Tests(ITestOutputHelper output)
        {
        var type = output.GetType();
        var testMember = type.GetField("test", BindingFlags.Instance | BindingFlags.NonPublic);
        var test = (ITest)testMember.GetValue(output);
        }
    <...>
      }
    

提交回复
热议问题