0

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?

Eric
  • 23
  • 5
  • You should probably have individual test cases for each functionality, instead of deciding which one to call based on some test parameter. – Morfic May 02 '18 at 08:55
  • I agree with you, Morfic. but that is how our leadership decided. – Eric May 02 '18 at 09:33
  • Well if they didn't give you a good reason, perhaps you can bring it up to discussion again, and provide your arguments why having individual tests for separate functionalities is beneficial, eg: improved readability, understanding, maintenance, debugging, easier to find the point of failure, etc (more on quality of a good unit test [here](https://stackoverflow.com/questions/61400/what-makes-a-good-unit-test)) – Morfic May 02 '18 at 11:29

1 Answers1

0

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.

Ishita Shah
  • 3,955
  • 2
  • 27
  • 51