What is the difference between @BeforeClass and @BeforeMethod?

There are two main differences between @BeforeClass and @BeforeMethod. They are as follows:

1. The method with @BeforeClass will be executed only once before any of the tests in the current class are run whereas, a method annotated with @BeforeMethod will be executed before
each method annotated with @Test.
2. @BeforeClass annotation can be used to set up the configuration and initialization which is common to all test methods in the current class. For example, we can set up driver configuration
which will be common for all tests in the class.
@BeforeMethod can be used to set that data which is repeating before each @Test annotated method.

Leave a Reply