TestNG MCQ
TestNG MCQ
3. What is the correct TestNG annotation to run a method after each test case?
A) @AfterSuite
B) @AfterTest
C) @AfterClass
D) @AfterMethod
4. How can you pass parameters from a TestNG XML file to a test method?
A) Using @DataProvider
B) Using @Parameters
C) Using @Test
D) Using @Optional
5. In TestNG, how do you ignore a test method without removing it from the code?
A) Remove the @Test annotation.
B) Use enabled=false in the @Test annotation.
C) Use @Ignore annotation.
D) Comment out the method code.
@Test(enabled = false)
public void ignoredTest() {
System.out.println("This test will be ignored.");
}
6. Which TestNG feature is used to run the same test with different sets of data?
A) @Factory
B) @DataProvider
C) @Parameters
D) @BeforeTest
7. What will happen if the dependsOnMethods attribute is used, but the dependent
method fails?
A) The dependent method will be skipped.
B) The dependent method will run regardless.
C) The dependent method will also fail.
D) The test execution will stop.
9. Which TestNG XML tag specifies the classes that contain test methods?
A) <test>
B) <suite>
C) <class>
D) <method>
10. What is the default execution order of the following annotations in TestNG?
@BeforeSuite
@BeforeTest
@BeforeClass
@BeforeMethod
@Test
@AfterMethod
@AfterClass
@AfterTest
@AfterSuite
13. What is the default value of the invocationCount attribute in the @Test
annotation?
A) 0
B) 1
C) 2
D) Unlimited
17. How can you ensure a test runs multiple times with different data sets in
TestNG?
A) @Factory
B) @DataProvider
C) @Test(invocationCount = x)
D) @RepeatTest
18. What happens if you set priority to the same value for multiple @Test methods?
A) Tests run alphabetically by method name.
B) Tests run in an undefined order.
C) Tests run in the order they are defined in the class.
D) Tests fail due to a conflict.