I have one class with tests, each test included in different groups. For all groups should be done some preparation to run the tests successfully. I'm using several @BeforeSuite for different test-groups.
Here is my example:
public class TestClass {
@BeforeSuite(groups = {"groupOne"})
public void setUpGroupOne(@Optional("parameter") String parameter) {
// some logic only for groupOne
}
@BeforeSuite(groups = {"groupTwo"})
public void setUpGroupTwo() {
// some logic only for groupTwo
}
@BeforeTest(alwaysRun = true)
public void onStart() {}
@BeforeMethod(alwaysRun = true)
public void prepareForTest() {}
@Test(groups = {"groupOne"})
public void testGroupOne() {
// some test steps with setUp for groupOne
}
@Test(groups = {"groupTwo"})
public void testGroupTwo() {
// some test steps with setUp for groupTwo
}
@AfterTest(alwaysRun = true)
public void onFinish() {}
@AfterMethod(alwaysRun = true)
public void cleanUpAfterTest() {}
}
If run group from xml-file - there are no problems at all, all methods runs only for related group.
But if I want to run only one test-method - for example, run just testGroupOne() from the my class - both @BeforeSuite methods are executed - for "groupOne" and for "groupTwo".
And the problem is the my test testGroupOne didn't get the necessary parameter which I'm applying in setUpGroupOne.
How I can to avoid running methods that not related to the group of my executed @Test when I'm run it from the class (not xml)?
Maybe there are any another solution for my task?