Saturday, September 21, 2024

Combination of all Annotations MCQ

1. What is TestNG primarily used for?

A) Data visualization

B) Continuous integration

C) Testing Java applications

D) Database management


Answer: C) Testing Java applications


2. Which annotation in TestNG is used to indicate a method that should be run before each test method?

A) @BeforeSuite

B) @BeforeTest

C) @BeforeMethod

D) @BeforeClass


Answer: C) @BeforeMethod


3. What is the default priority of a TestNG test method if no priority is specified?

A) 0

B) 1

C) 10

D) -1


Answer: A) 0


4. Which of the following files is used to configure TestNG test cases?

A) testng.xml

B) junit.xml

C) config.xml

D) test-config.xml


Answer: A) testng.xml


5. How can you define a group of test methods in TestNG?

A) Using the @Group annotation

B) Using the @Test annotation with groups attribute

C) Using the @Categories annotation

D) Using the @TestGroup annotation


Answer: B) Using the @Test annotation with groups attribute


6. Which TestNG annotation is used to execute a method after all tests in the current class are run?

A) @AfterSuite

B) @AfterTest

C) @AfterMethod

D) @AfterClass


Answer: D) @AfterClass


7. What is the purpose of the @DataProvider annotation in TestNG?

A) To provide test data to a test method

B) To provide configuration data to the TestNG suite

C) To define test groups

D) To create a new test suite


Answer: A) To provide test data to a test method



9. In TestNG, which annotation is used to run methods in a specific order?

A) @Order

B) @TestOrder

C) @Test(priority)

D) @Sequence


Answer: C) @Test(priority)



Here are some multiple-choice questions (MCQs) specifically focused on the @Test annotation in TestNG:


1. What is the primary function of the @Test annotation in TestNG?

A) To define a setup method for tests

B) To mark a method as a test method

C) To group multiple test methods

D) To specify a method to run after all tests


Answer: B) To mark a method as a test method


2. How do you specify the expected exception that a test method should throw using the @Test annotation?

A) @Test(expectedExceptions = Exception.class)

B) @Test(throws = Exception.class)

C) @Test(exception = Exception.class)

D) @Test(expect = Exception.class)


Answer: A) @Test(expectedExceptions = Exception.class)


3. What does the enabled attribute of the @Test annotation control?

A) Whether the test method is included in the test suite

B) The execution order of the test method

C) The priority of the test method

D) The timeout for the test method


Answer: A) Whether the test method is included in the test suite


4. How can you assign a priority to a test method in TestNG?

A) @Test(priority = 1)

B) @Test(order = 1)

C) @Test(level = 1)

D) @Test(sequence = 1)


Answer: A) @Test(priority = 1)


5. How can you group test methods using the @Test annotation?

A) @Test(groups = {"group1", "group2"})

B) @Test(categories = {"group1", "group2"})

C) @Test(groups = {"group1", "group2"}, priority = 1)

D) @Test(group = {"group1", "group2"})


Answer: A) @Test(groups = {"group1", "group2"})


6. What does the timeOut attribute in the @Test annotation specify?

A) The maximum time a test method can run before being terminated

B) The maximum number of retries for a test method

C) The delay before the test method starts

D) The minimum time between test method executions


Answer: A) The maximum time a test method can run before being terminated


7. Can you use the @Test annotation on methods in a class that extends another class with @Test methods?

A) Yes, TestNG will consider inherited test methods as well.

B) No, TestNG only considers methods annotated in the current class.

C) Only if the parent class is in the same package.

D) Only if the parent class is annotated with @Test at the class level.


Answer: A) Yes, TestNG will consider inherited test methods as well.


8. What does the invocationCount attribute in the @Test annotation specify?

A) The number of times a test method should be invoked

B) The number of parameters a test method can have

C) The number of groups a test method can belong to

D) The number of times a test method is skipped


Answer: A) The number of times a test method should be invoked


9. How can you specify that a test method should run only if certain conditions are met?

A) Use @Test(enabled = true/false)

B) Use @Test(condition = "condition")

C) Use @Test(dependsOnMethods = "methodName")

D) Use @Test(prerequisite = "methodName")


Answer: C) Use @Test(dependsOnMethods = "methodName")


10. If a test method is marked with @Test and has a timeout of 1000 milliseconds, what will happen if the method runs longer than this?

A) The test will pass but with a warning

B) The test will fail and be marked as a timeout failure

C) The test will automatically retry

D) The test will be skipped


Answer: B) The test will fail and be marked as a timeout failure


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...