Saturday, September 21, 2024

TestNG Annontations2 MCQ

 Here are some multiple-choice questions (MCQs) focused on the TestNG annotations: @BeforeTest, @AfterTest, @BeforeMethod, @AfterMethod, @BeforeSuite, @BeforeClass, and @AfterClass.


1. What is the purpose of the @BeforeTest annotation in TestNG?

A) To execute a method before each test method in a class

B) To execute a method before all tests in a test suite

C) To execute a method before any test method in the <test> tag of the testng.xml file

D) To execute a method before every class in the suite


Answer: C) To execute a method before any test method in the <test> tag of the testng.xml file


2. Which TestNG annotation is used to run a method after all the test methods in the <test> tag of the testng.xml file have run?

A) @AfterMethod

B) @AfterClass

C) @AfterSuite

D) @AfterTest


Answer: D) @AfterTest


3. What does the @BeforeMethod annotation do in TestNG?

A) It runs before every method in the entire suite

B) It runs before each test method in the current class

C) It runs before all methods in the test suite

D) It runs before the first method of the class


Answer: B) It runs before each test method in the current class


4. When is the @AfterMethod annotation executed in TestNG?

A) After all test methods in the test class have run

B) After every test method in the current class has run

C) After the entire test suite has run

D) After the test methods in the <test> tag have run


Answer: B) After every test method in the current class has run


5. Which annotation should you use if you want to run a setup method before all test methods in a class are executed?

A) @BeforeSuite

B) @BeforeTest

C) @BeforeClass

D) @BeforeMethod


Answer: C) @BeforeClass


6. What is the function of the @AfterClass annotation in TestNG?

A) To run a method after all test methods in a class have been executed

B) To run a method after every test method in a class

C) To run a method after the entire test suite has completed

D) To run a method after all test methods in the <test> tag have completed


Answer: A) To run a method after all test methods in a class have been executed


7. When is the @BeforeSuite annotation used in TestNG?

A) Before each test method is executed

B) Before each test class is executed

C) Before all tests in a suite are executed

D) Before each method in a suite is executed


Answer: C) Before all tests in a suite are executed


8. Which of the following annotations is executed only once before all test methods in a suite?

A) @BeforeTest

B) @BeforeMethod

C) @BeforeClass

D) @BeforeSuite


Answer: D) @BeforeSuite


9. In what order are the following annotations executed in TestNG: @BeforeSuite, @BeforeClass, @BeforeMethod?

A) @BeforeMethod, @BeforeClass, @BeforeSuite

B) @BeforeSuite, @BeforeClass, @BeforeMethod

C) @BeforeClass, @BeforeSuite, @BeforeMethod

D) @BeforeSuite, @BeforeMethod, @BeforeClass


Answer: B) @BeforeSuite, @BeforeClass, @BeforeMethod


10. Which TestNG annotation is suitable for cleaning up resources after all tests in a suite have been executed?

A) @AfterClass

B) @AfterTest

C) @AfterMethod

D) @AfterSuite


Answer: D) @AfterSuite

No comments:

Post a Comment

git commands MCQ

 Here are some multiple-choice questions (MCQs) on Git commands relevant for Selenium: 1. Which Git command is used to clone a remote reposi...