What is @BeforeMethod?

@BeforeMethod is one of the TestNG Annotations. As the name itself defines, @BeforeMethod is executed before each test method within a test class. Suppose there are n test methods within a test class, then n times @BeforeMethod annotated method will be invoked. This annotation allows developers to specify various actions to be taken before test methods are run.

TestNG @BeforeMethod Annotations

The Concept Annotations is introduced in Java 1.5. The Popular Annotation in Java is @override. We use the same annotation concept in TestNG.

In TestNG, there are 10 Annotations:

In this article, we will learn about @BeforeMethod.

Similar Reads

What is @BeforeMethod?

@BeforeMethod is one of the TestNG Annotations. As the name itself defines, @BeforeMethod is executed before each test method within a test class. Suppose there are n test methods within a test class, then n times @BeforeMethod annotated method will be invoked. This annotation allows developers to specify various actions to be taken before test methods are run....

Example of @BeforeMethod

Let’s understand the @BeforeMethod annotation through an example....