With TestNG, you would use for this group:
@BeforeMethod(groups = "g1") public void setUp1(){ obj.addDataThisWay(data); } @BeforeMethod(groups = "g2") public void setUp2(){ obj.addDataThatWay(data); } @Test(groups = { "g1", "g2" }) public void testResult(){ assertEquals(obj.getResult(),1); }
If you ask TestNG to run the "g1" group, it will run setUp1 () -> testResult. If you run the "g2" group, it will run setUp2 () -> testResult.
In addition, like the commentator mentioned above, you can use data providers to pass various parameters to your testing method:
//This method will provide data to any test method that declares that its Data Provider //is named "test1" @DataProvider(name = "test1") public Object[][] createData1() { return new Object[][] { { "Cedric", new Integer(36) }, { "Anne", new Integer(37)}, }; } //This test method declares that its data should be supplied by the Data Provider //named "test1" @Test(dataProvider = "test1") public void verifyData1(String n1, Integer n2) { System.out.println(n1 + " " + n2); }
source share