I need to prepare some data before running some test methods in my test class. But these data will be used only in 5 test methods only. The entire test class has 25 test cases.

So is there any way to trigger before Method only for specific test methods. In my case, only for above 4 test methods? Its Java, TestNg

1 Answer 1


You could create another method that does not have the @Test or @BeforeMethod/@BeforeTest tags and then just call that method within the tests themselves.


You could use the @DataProvider tag to provide the data and then reference it with the tests like @Test(dataProvider="nameOfDataProvider")

It's hard to know for sure without seeing the code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.