在NUnit 3中。x、 只需使用
TestContext.CurrentContext.Test.Name
Test
喜欢
MethodName
或
FullName
取决于你需要什么。
[TestFixture]
public class TestNameInSetup
{
[SetUp]
public void SetUp()
{
var testName = TestContext.CurrentContext.Test.Name;
TestContext.WriteLine($"SetUp for {testName}");
}
[Test]
public void NamedTest()
{
var testName = TestContext.CurrentContext.Test.Name;
TestContext.WriteLine($"Running test {testName}");
}
}