Can I use multiple @BeforeMethod methods that will only work for the groups they belong to?

@BeforeMethod (groups={"a"})
public void setup1() {
    //do something
}

@BeforeMethod (groups={"b"})
public void setup2() {
    //do something else
}

@Test (groups={"a"})
public void Test1() {
    //do something
}

@Test (groups={"b"})
public void Test2() {
    //do something
}

@Test (groups={"a"})
public void Test3() {
    //do something
}

@Test (groups={"b"})
public void Test4() {
    //do something
}

      

while the xml file will look something like this:

<run>
    <include name="a"/>
    <include name="b"/>
</run>

      

Is it possible to run only setup1 before Test1, Test3 while only setup2 is running before Test2, Test4?

+3


source to share


1 answer


What you need to use is @BeforeGroups, not @BeforeMethod. BeforeMethod ensures that setup1 and setup2 are executed before each method. BeforeGroups will ensure that it only runs before a specific group run is triggered.



+2


source







All Articles