自动化用例中如何获得testcase名称

JUnit

1
2
3
4
5
6
7
8
9
10
11
12
@Rule
public TestName testName = new TestName();

@Test
public void testcase_001(){
System.out.println(testName.getMethodName());
}

@Test
public void testcase_002(){
System.out.println(testName.getMethodName());
}

运行输出

1
2
testcase_001
testcase_002

TestNG

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
String testcaseName = "";

@BeforeMethod
public void beforeMethod(Method method) {
testcaseName = method.getName();
}

@Test
public void testcase_001() {
System.out.println(testcaseName);
}

@Test
public void testcase_002() {
System.out.println(testcaseName);
}

运行输出:

1
2
testcase_001
testcase_002

自动化用例中如何获得testcase名称
https://skynetboys.github.io/2020/12/05/自动化用例中如何获得testcase名称/
Author
Edison
Posted on
December 5, 2020
Licensed under