我正在使用 NUnit 和 Selenium WebDriver 编写 Web 测试。在每次测试结束时,我想获取浏览器的屏幕截图并保存图像。我希望图像名称与Test
名称相同。但我无法获得测试方法名称。
下面是测试方法:
[Test]
public void AbcTest_ShouldPass()
{
Assert.AreEqual(true, true);
}
这TearDown
是在每个之后运行的Test
:
[TearDonw]
[MethodImpl(MethoImplOptions.NoInlining)]
public void TestCleanupNunit()
{
var methodName = new List<string>();
for (int i = 0; i < 30; i++)
methodName.Add(i.ToString() + " is " + new StackTrace(i, true).GetFrame(0).GetMethod().Name);
}
但是当我看的时候methodName
,我找不到AbcTest_ShouldPass
。
0 is TestCleanupNUnit
1 is InvokeMethod
2 is UnsafeInvokeInternal
3 is Invoke
4 is Invoke
5 is InvokeMethod
6 is InvokeMethod
7 is RunTearDown
8 is RunTest
9 is RunTest
10 is RunRepeatedTest
11 is RunTestInContext
12 is Run
13 is RunAllTests
14 is RunSuite
15 is RunSuiteInContext
16 is Run
17 is Run
18 is RunAllTests
19 is RunSuite
20 is RunSuiteInContext
21 is Run
22 is RunAllTests
23 is RunSuite
24 is RunSuiteInContext
25 is Run
26 is RunAllTests
27 is RunSuite
28 is RunSuiteInContext
29 is Run
我看了这篇文章,但它对我没有帮助。