300+ TOP TestNG MCQ Questions and Answers Quiz

TestNG Multiple Choice Questions

1. What is meant by NG in TestNG?

  1. New Generation
  2. Next Generation
  3. Name Generation
  4. No Generation

Answer: B Next Generation

Explanation: NG in TestNG means Next Generation.

2. What is TRUE about TestNG?

  1. With TestNG, you are in complete control of what is happening in the test cases and how they are executed.
  2. Prior to running test case X, run multiple test cases as a pre-request.
  3. By utilizing easy annotations, grouping, sequencing, and parametrizing, the TestNG framework eliminates the limitations of the older framework.
  4. All of the above

Answer: D All of the above

Explanation: The things TRUE about TestNG are –

  1. With TestNG, you are in complete control of what is happening in the test cases and how they are executed.
  2. Prior to running test case X, run multiple test cases as a pre-request.
  3. By utilizing easy annotations, grouping, sequencing, and parametrizing, the TestNG framework eliminates the limitations of the older framework.

3. What is/are the advantage(s) of TestNG?

  1. It is easier to understand annotations in TestNG than in Junit.
  2. For implementation, it produces HTML reports.
  3. Logs are also generated by it.
  4. All of the above

Answer: D All of the above

Explanation: The advantages of TestNG are –

  1. It is easier to understand annotations in TestNG than in Junit.
  2. For implementation, it produces HTML reports.
  3. Logs are also generated by it.

4. Unlike Junit, TestNG does not have constraints like ____.

  1. @beforeclass
  2. @afterclass
  3. Both A and B
  4. None of the above

Answer: C Both A and B

Explanation: Unlike Junit, TestNG does not have constraints like @beforeclass and @afterclass.

5. TestNG is also known as –

  1. Testing Frame
  2. Testing Framework
  3. Testing Final
  4. Testing Phenomena

Answer: B Testing Framework

Explanation: TestNG is also known as Testing Framework.

6. A more powerful and easier-to-use framework, TestNG framework came ____ JUnit.

  1. Before
  2. After
  3. Alongwith
  4. None

Answer: B After

Explanation: A more powerful and easier-to-use framework, TestNG framework came after Junit.

7. ____ are all supported by TestNG.

  1. A suite before/after
  2. A test before/after
  3. A group of tests before/after
  4. All of the above

Answer: D All of the above

Explanation: A suite before/after, a test before/after, or a group of tests before/after are all supported by TestNG.

8. In the TestNG framework, test cases can be defined ____ one another.

  1. Dependently on
  2. Independently of
  3. Interdependently on
  4. Intradependently on

Answer: B Independently of

Explanation: In the TestNG framework, test cases can be defined independently of one another.

9. Which of the following ways can be used to add TestNG in your Eclipse?

  1. TestNG can be installed either by adding the TestNG jar file to the Build Path or by installing the TestNG plug-in.
  2. The TestNG plug-in is preferable to the testng.jar file since you don’t have to install it for every project. Testng.jar files, on the other hand, must be added to every project’s build path.
  3. Both A and B
  4. None of the above

Answer: C Both A and B

Explanation: The following ways can be used to add TestNG in your eclipse –

  1. TestNG can be installed either by adding the TestNG jar file to the Build Path or by installing the TestNG plug-in.
  2. The TestNG plug-in is preferable to the testng.jar file since you don’t have to install it for every project. Testng.jar files, on the other hand, must be added to every project’s build path.

10. What is/are the feature(s) of TestNG?

  1. Before and After annotations
  2. Dependent methods
  3. Better reporting
  4. All of the above

Answer: D All of the above

Explanation: The features of TestNG are –

  1. Before and After annotations
  2. Dependent methods
  3. Better reporting

11. It is possible to execute specific code ____ testing by using before and after annotations.

  1. Before
  2. After
  3. Both A and B
  4. None of the above

Answer: C Both A and B

Explanation: It is possible to execute specific code before and after testing by using before and after annotations.

12. In order to set variables or configuration ____ executing a test method, and to clean up all variables afterward, before and after annotations are used.

  1. Before
  2. After
  3. While
  4. None

Answer: A Before

Explanation: In order to set variables or configuration before executing a test method, and to clean up all variables afterward, before and after annotations are used.

13. Annotations like ____, or @BeforeClass are examples of Before and After annotations.

  1. @BeforeSuite
  2. @BeforeTest
  3. @BeforeGroups
  4. All of the above

Answer: D All of the above

Explanation: Annotations like @BeforeSuite, @BeforeTest, @BeforeGroups, or @BeforeClass are examples of Before and After annotations.

14. ____-based files are used to configure TestNG test suites.

  1. HTML
  2. CSS
  3. XML
  4. PHP

Answer: C XML

Explanation: XML-based files are used to configure Testng test suites.

15. The test suites are organized and run using the ____ file.

  1. Testng.html
  2. Testng.xml
  3. Testng.php
  4. Testng.pl

Answer: B Testng.xml

Explanation: The test suites are organized and run using the Testng.xml file.

16. A testng.xml file defines ____, and test groups that are used to create test suites.

  1. Classes
  2. Methods
  3. Packages
  4. All of the above

Answer: D All of the above

Explanation: A testng.xml file defines classes, methods, packages, and test groups that are used to create test suites.

17. Using Testng’s dependencies, a test method can be ____ on one or more other test methods.

  1. Interdependent
  2. Intradependent
  3. Independent
  4. Dependent

Answer: D Dependent

Explanation: Using Testng’s dependencies, a test method can be dependent on one or more other test methods.

18. Based on the ‘____’ principle, dependencies work only when they are in the same class or in the inherited base class.

  1. No-depend-method
  2. Depend-on-method
  3. Depend-to-method
  4. None-depend-method

Answer: B Depend-on-method

Explanation: Based on the ‘depend-on-method’ principle, dependencies work only when they are in the same class or in the inherited base class.

19. It is possible to parameterize test methods by passing arguments as parameters, which is achieved by using ____ annotations.

  1. testing@Parameters
  2. testng@Parameters
  3. Parameters@testng
  4. Parameters@testing

Answer: B testng@Parameters

Explanation: It is possible to parameterize test methods by passing arguments as parameters, which is achieved by using testng@Parameters annotations.

20. ____ files can be used to pass parameters to test methods.

  1. DataProviders
  2. Testng.xml
  3. Both A and B
  4. None of the above

Answer: C Both A and B

Explanation: DataProviders and testng.xml files can be used to pass parameters to test methods.

21. Using the ____ method, multiple sets of data are used to execute the test method.

  1. DataFetcher
  2. DataAddition
  3. DataProvider
  4. DataModification

Answer: C DataProvider

Explanation: Using the DataProvider method, multiple sets of data are used to execute the test method.

22. Parallel execution of tests is known as ____.

  1. Better Reporting
  2. Multithreaded Execution
  3. Data-Driven Testing
  4. Parameterization of Test Methods

Answer: B Multithreaded Execution

Explanation: Parallel execution of tests is known as multithreaded execution.

23. Test methods are executed in multiple threads based on the configuration in the ____ file.

  1. HTML
  2. CSS
  3. XML
  4. C

Answer: C XML

Explanation: Test methods are executed in multiple threads based on the configuration in the XML file.

24. Reports for test execution using TestNG are provided in ____ formats by default.

  1. XML
  2. HTML
  3. Both A and B
  4. None of the above

Answer: C Both A and B

Explanation: Reports for test execution using TestNG are provided in XML and HTML formats by default.

25. Java allows only one test to be defined in a single class in the main() method, while TestNG allows ____ tests in a single class.

  1. Two
  2. Three
  3. Four
  4. Multiple

Answer: D Multiple

Explanation: Java allows only one test to be defined in a single class in the main() method, while TestNG allows multiple tests in a single class.

26. By using the @____ annotation, you can create multiple test cases.

  1. Test
  2. Before
  3. After
  4. BeforeClass

Answer: A Test

Explanation: By using the @Test annotation, you can create multiple test cases.

27. There is a feature in TestNG that allows you to ____ test cases.

  1. Enable
  2. Disable
  3. Both A and B
  4. None of the above

Answer: C Both A and B

Explanation: There is a feature in TestNG that allows you to enable or disable test cases.

28. In how many ways can test cases be disabled in TestNG?

  1. 2
  2. 3
  3. 4
  4. 5

Answer: A 2

Explanation: Test cases can be disabled in two ways in TestNG.

29. By which of the following way(s) can the test cases be disabled in TestNG?

  1. @Test annotations allow you to disable test cases.
  2. XML files can be edited to disable test cases.
  3. Both A and B
  4. None of the above

Answer: C Both A and B

Explanation: By the following ways the test cases can be disabled in TestNG –

  1. @Test annotations allow you to disable test cases.
  2. XML files can be edited to disable test cases.

30. A TestNG ____ is a piece of code that comes into play during test execution and controls the flow of the test.

  1. Groups
  2. Annotation
  3. Code
  4. Tags

Answer: B Annotation

Explanation: A TestNG Annotation is a piece of code that comes into play during test execution and controls the flow of the test.

31. Which of the following is/are the TestNG Annotation(s)?

  1. @BeforeSuite
  2. @AfterSuite
  3. @BeforeTest
  4. All of the above

Answer: D All of the above

Explanation: The following are the TestNG Annotations –

  1. @BeforeSuite
  2. @AfterSuite
  3. @BeforeTest

32. All test methods in the suite will be executed before the @____ method runs.

  1. BeforeSuite
  2. BeforeClass
  3. BeforeTest
  4. BeforeMethod

Answer: A BeforeSuite

Explanation: All test methods in the suite will be executed before the @BeforeSuite method runs.

33. After all test methods in a suite have been executed, the @____ annotation will run.

  1. AfterSuite
  2. AfterTest
  3. AfterClass
  4. AfterMethod

Answer: A AfterSuite

Explanation: After all test methods in a suite have been executed, the @AfterSuite annotation will run.

34. All test methods in that folder will be executed before the @____ annotated method is executed.

  1. BeforeClass
  2. BeforeSuite
  3. BeforeTest
  4. BeforeMethod

Answer: C BeforeTest

Explanation: All test methods in that folder will be executed before the @BeforeTest annotated method is executed.

35. Upon completion of all the test methods of the classes in the folder, the @____ method will be executed.

  1. AfterSuite
  2. AfterTest
  3. AfterClass
  4. AfterMethod

Answer: B AfterTest

Explanation: Upon completion of all the test methods of the classes in the folder, the @AfterTest method will be executed.

36. This method is called before the class’s first method is invoked using the @____ annotation.

  1. BeforeSuite
  2. BeforeClass
  3. BeforeTest
  4. BeforeMethod

Answer: B BeforeClass

Explanation: This method is called before the class’s first method is invoked using the @BeforeClass annotation.

37. After all test methods of the current class have been executed, the @____ method will be invoked.

  1. AfterMethod
  2. AfterSuite
  3. AfterClass
  4. AfterTest

Answer: C AfterClass

Explanation: After all test methods of the current class have been executed, the @AfterClass method will be invoked.

38. Every test method will be run prior to the @____ annotation.

  1. BeforeMethod
  2. BeforeTest
  3. BeforeClass
  4. BeforeSuite

Answer: A BeforeMethod

Explanation: Every test method will be run prior to the @BeforeMethod annotation.

39. After each test method is executed, the @____ annotation is executed.

  1. AfterTest
  2. AfterClass
  3. AfterMethod
  4. AfterSuite

Answer: C AfterMethod

Explanation: After each test method is executed, the @AfterMethod annotation is executed.

40. Before all test cases in a group are executed, the @____ annotation is run only once.

  1. BeforeTest
  2. BeforeClass
  3. BeforeSuite
  4. BeforeGroups

Answer: D BeforeGroups

Explanation: Before all test cases in a group are executed, the @BeforeGroups annotation is run only once.

41. After the execution of all test cases belonging to a group, the @____ annotated method runs only once.

  1. AfterTest
  2. AfterGroups
  3. AfterSuite
  4. AfterClass

Answer: B AfterGroups

Explanation: After the execution of all test cases belonging to a group, the @AfterGroups annotated method runs only once.

42. Which of the following comes first in the hierarchy of TestNG Annotations?

  1. BeforeSuite
  2. BeforeClass
  3. BeforeTest
  4. BeforeMethod

Answer: A BeforeSuite

Explanation: BeforeSuite comes first in the hierarchy of TestNG Annotations.

43. Which of the following comes last in the hierarchy of TestNG Annotations?

  1. AfterClass
  2. AfterTest
  3. AfterSuite
  4. AfterMethod

Answer: C AfterSuite

Explanation: AfterSuite comes last in the hierarchy of TestNG Annotations.

44. What is/are the benefit(s) of TestNG Annotations?

  1. It was very easy for testers to work with TestNG Annotations.
  2. The additional parameters can be passed to TestNG Annotations.
  3. A test class does not need to be extended to use TestNG annotations.
  4. All of the above

Answer: D All of the above

Explanation: The benefits of TestNG Annotations are –

  1. It was very easy for testers to work with TestNG Annotations.
  2. The additional parameters can be passed to TestNG Annotations.
  3. A test class does not need to be extended to use TestNG annotations.

45. What is/are the TestNG Annotation Attribute(s)?

  1. Description
  2. TimeOut
  3. Priority
  4. All of the above

Answer: D All of the above

Explanation: The TestNG Annotation Attributes are –

  1. Description
  2. TimeOut
  3. Priority

46. An @Test annotation contains a string called ____ that describes the test.

  1. Priority
  2. Enabled
  3. Description
  4. TimeOut

Answer: C Description

Explanation: An @Test annotation contains a string called description that describes the test.

47. The “____” attribute can be used when the second test method wants to be dependent on the first.

  1. Priority
  2. TimeOut
  3. dependOnMethods
  4. Groups

Answer: C dependOnMethods

Explanation: The “dependOnMethods” attribute can be used when the second test method wants to be dependent on the first.

48. The TestNG will run the test cases ____ if the ‘priority’ attribute is not specified.

  1. Alphabetically
  2. Numerically
  3. Alphanumerically
  4. Randomly

Answer: A Alphabetically

Explanation: The TestNG will run the test cases alphabetically if the ‘priority’ attribute is not specified.

49. A test case’s ____ determines its execution sequence.

  1. Priority
  2. Groups
  3. TimeOut
  4. dependOnMethods

Answer: A Priority

Explanation: A test case’s priority determines its execution sequence.

50. -_000 to _000 are the integer values that can be stored in the priority.

  1. 4
  2. 5
  3. 6
  4. 7

Answer: B 5

Explanation: -5000 to 5000 are the integer values that can be stored in the priority.

51. Priority settings determine how the test cases are executed, with the lowest priority running ____ and the highest priority running ____.

  1. First, Last
  2. Last, First
  3. Middle, Last
  4. Middle, First

Answer: A First, Last

Explanation: Priority settings determine how the test cases are executed, with the lowest priority running first and the highest priority running last.

52. ‘____’ contains a boolean value that is set to true by default.

  1. TimeOut
  2. Priority
  3. Enabled
  4. Groups

Answer: C Enabled

Explanation: ‘enabled’ contains a boolean value that is set to true by default.

53. Different test cases belonging to the same functionality are grouped using the ‘____’ attribute.

  1. TimeOut
  2. Priority
  3. Groups
  4. Enabled

Answer: C Groups

Explanation: Different test cases belonging to the same functionality are grouped using the ‘groups’ attribute.

54. Testing cases are provided with a ____ during which they can complete their execution.

  1. timeIn
  2. timeOut
  3. timeZone
  4. Time

Answer: B timeOut

Explanation: Testing cases are provided with a timeOut during which they can complete their execution.

55. A test method can be parameterized in ___ ways.

  1. Two
  2. Three
  3. Four
  4. Five

Answer: A Two

Explanation: A test method can be parameterized in two ways.

56. A test method can be parameterized in the following way(s) –

  1. TestNG Parameters
  2. TestNG DataProviders
  3. Both A and B
  4. None of the above

Answer: C Both A and B

Explanation: A test method can be parameterized in the following ways –

  1. TestNG Parameters
  2. TestNG DataProviders

57. Annotations like @____ in TestNG enable you to listen to every event in your Selenium code.

  1. Speakers
  2. Listeners
  3. Ears
  4. Earpods

Answer: B Listeners

Explanation: Annotations like @Listeners in TestNG enable you to listen to every event in your Selenium code.

58. It is possible to activate the listeners ____ the test case.

  1. Before
  2. After
  3. Both A and B
  4. None of the above

Answer: C Both A and B

Explanation: It is possible to activate the listeners either before or after the test case.

59. A listener is implemented by an interface called ____.

  1. TestListener
  2. ITestListener
  3. IListener
  4. Listener

Answer: B ITestListener

Explanation: A listener is implemented by an interface called ITestListener.

60. Which of the following is/are the method(s) in ITestListener Interface?

  1. onTestStart()
  2. onTestSuccess()
  3. onTestFailure()
  4. All of the above

Answer: D All of the above

Explanation: The following are the methods in ITestListener Interface –

  1. onTestStart()
  2. onTestSuccess()
  3. onTestFailure()

TestNG objective questions with answers pdf download online exam test

Leave a Reply

Your email address will not be published. Required fields are marked *