Recall & Review
beginner
What is the purpose of the @Test annotation in TestNG?
The @Test annotation marks a method as a test case that TestNG will run. It tells TestNG this method contains test code to execute.
Click to reveal answer
beginner
Explain the role of @BeforeMethod in TestNG.
@BeforeMethod runs before each @Test method. It is used to set up preconditions or initialize resources needed for the test.
Click to reveal answer
beginner
What does the @AfterMethod annotation do in TestNG?
@AfterMethod runs after each @Test method. It is used to clean up or release resources after the test finishes.
Click to reveal answer
intermediate
In what order do @BeforeMethod, @Test, and @AfterMethod run?
For each test method, TestNG runs @BeforeMethod first, then the @Test method, and finally @AfterMethod.
Click to reveal answer
intermediate
Why is it useful to use @BeforeMethod and @AfterMethod instead of putting setup and cleanup code inside @Test methods?
Using @BeforeMethod and @AfterMethod avoids repeating setup and cleanup code in every test. It keeps tests clean and easier to maintain.
Click to reveal answer
Which TestNG annotation is used to mark a method as a test case?
✗ Incorrect
@Test marks a method as a test case to be executed by TestNG.
When does a method annotated with @BeforeMethod run?
✗ Incorrect
@BeforeMethod runs before each individual @Test method.
What is the main purpose of @AfterMethod?
✗ Incorrect
@AfterMethod is used to clean up or release resources after each test.
If you have 3 @Test methods, how many times will @BeforeMethod run?
✗ Incorrect
@BeforeMethod runs before each @Test method, so it runs 3 times for 3 tests.
Which annotation would you use to prepare test data before each test?
✗ Incorrect
@BeforeMethod is used to set up or prepare data before each test.
Describe how @BeforeMethod, @Test, and @AfterMethod work together in a TestNG test class.
Think about what happens before, during, and after each test method.
You got /3 concepts.
Explain why using @BeforeMethod and @AfterMethod can improve test code quality compared to putting setup and cleanup inside @Test methods.
Consider how repeating code affects your tests.
You got /3 concepts.