lundi 29 mai 2017

How to set test group to @Test methods dynamically using TestNG?

I want to set group to a particular @Test method at runtime depending on some condition

Suppose I have the following classes

public class MyTest1{
  @Test
  public void test1(){
    System.out.println("test1 called");
  }
}

public class MyTest2{
  @Test(groups={"group1"})
  public void test2(){
    System.out.println("test2 called");
  }

  @Test(groups={"group2"})
  public void test3(){
    System.out.println("test3 called");
  }
}

Now while running test I am sending "-groups group1" or "-groups group2" to TestNG in command line. So testng is running either test2() or test3() depending on the group name passed. Now my requirement is to run test1() that is not supposed have any groups attached. Whatever group I provide to testng runner this test1() should be run every time. I tried with implementing alter method of IAlterSuiteListener but I could not get all the test methods including which are not considered to run. So I could not set the group name at runtime.

So is there any other way to set groups to @Test methods (having no groups defined) at runtime?

Aucun commentaire:

Enregistrer un commentaire