What is the purpose of the @BeforeClass annotation in TestNG?

What is the purpose of the @BeforeClass annotation in TestNG?

A) To execute a method before all methods in a class
B) To execute a method after all methods in a class
C) To execute a method before each method in a class
D) To execute a method after each method in a class

Answer:

A) To execute a method before all methods in a class

Explanation:

The @BeforeClass annotation in TestNG is used to execute a method before all test methods in a class are run. This annotation is typically used for setup tasks that need to be performed before any test methods in the class are executed.

For example:


@BeforeClass
public void setUpClass() {
    // Code to set up before all test methods in the class
}

In this example, setUpClass() will be executed once before any of the test methods in the class are run.

Reference links:

https://www.javaguides.net/p/top-java-libraries.html

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top