mercredi 11 décembre 2019

How to execute for loop for all test cases using the base class @BeforeMethod in Junit

Let's say I have a Base class:

Class BaseClass{

  @BeforeClass
  public static void testBefore(){
     //some work done here

  }
}

Class TestClass extends BaseClass{

  @Test
  public void testmethod1(){
     for (String x: listOfX){
      // some other assertions here here
     }
  }

  @Test
  public void testmethod2(){
     for (String x: listOfX){
      // some other assertions here here
     }
  }
}

My question is what would be a good way to avoid these for loops within each testmethod(). Is there a way to move this for loop in @BeforeMethod etc so that testMethod() executes once per X. Your suggestions are very much appreciated and thank you for your time.

Aucun commentaire:

Enregistrer un commentaire