Search code examples
javatestngextentreports

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


I am executing test cases based on few constants such as if ADD come then only perform Add functionality and so on... and test cases are executing. I would like to retrieve test case name/ description. Below is my pseudo code for the test case

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

name is a variable which I am getting from a property file. so I would like to have test case names are 1. "Add" + name 2. "Edit" +name 3."delete" +name Can some one please advise me on this?


Solution

  • You can pass by string value,

    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);        
    }
    

    I didn't find For loop in your code, But if it is there we can use it similarly.