Google News
logo
JUnit - Interview Questions
What is @Before and @BeforeClass and it's usage?
@Before annotation :
 
syntax :
@Before
public void myMethod()
 
This method should execute before each test. Such methods are generally used for initialization before performing a actual test in test environment.


@BeforeClass annotation :
 
syntax :
@BeforeClass
public static void myMethod()
 
This method should execute before all the tests. It executes only once. Method should be declared static. Mostly used for database connectivity tasks before execution of any of the test.
Advertisement