如何在for循环中执行测试用例时使用testNG获取测试用例描述/测试用例名称

How to get Test case Description / Name of test case using testNG when testcases are executing in for loop

我正在执行基于几个常量的测试用例,例如如果 ADD 出现则只执行添加功能等等......并且测试用例正在执行。我想检索测试用例名称/描述。 下面是我的测试用例伪代码

@Test
public void executeTestStep(String name) {
    if (A.get() == ADD) {
        performAdd(name);
    } else  (A.get() == EDIT) {
        perform(name);
    }          }

name 是我从 属性 文件中获取的变量。所以我想测试用例名称是 1. "Add" + 姓名 2. "Edit" +姓名 3."delete" +姓名 有人可以就此给我一些建议吗?

你可以通过字符串值传递,

String testCase="";

@Test
public void executeTestStep(String name) {
    if (A.get() == ADD) {
        performAdd(name);
        testCase = "Add Operation";
    } else  (A.get() == EDIT) {
        perform(name);
         testCase = "Edit Operation";
    }  
System.out.println("Test Case: " +testCase);        
}

我没有在你的代码中找到 For 循环,但如果有,我们可以类似地使用它。