TestNG is a testing framework for the Java programming language created by Cédric Beust and inspired by JUnit and NUnit.
TestNG MCQs: This section contains multiple-choice questions and answers on the various topics of TestNG. Practice these MCQs to test and enhance your skills on TestNG.
List of TestNG MCQs
1. TestNG is also known as –
- Testing Frame
- Testing Framework
- Testing Final
- Testing Phenomena
Answer: B) Testing Framework
Explanation:
TestNG is also known as Testing Framework.
2. A more powerful and easier-to-use framework, TestNG framework came ____ JUnit.
- Before
- After
- Alongwith
- None
Answer: B) After
Explanation:
A more powerful and easier-to-use framework, TestNG framework came after Junit.
3. What is meant by NG in TestNG?
- New Generation
- Next Generation
- Name Generation
- No Generation
Answer: B) Next Generation
Explanation:
NG in TestNG means Next Generation.
4. What is TRUE about TestNG?
- With TestNG, you are in complete control of what is happening in the test cases and how they are executed.
- Prior to running test case X, run multiple test cases as a pre-request.
- By utilizing easy annotations, grouping, sequencing, and parametrizing, the TestNG framework eliminates the limitations of the older framework.
- All of the above
Answer: D) All of the above
Explanation:
The things TRUE about TestNG are –
- With TestNG, you are in complete control of what is happening in the test cases and how they are executed.
- Prior to running test case X, run multiple test cases as a pre-request.
- By utilizing easy annotations, grouping, sequencing, and parametrizing, the TestNG framework eliminates the limitations of the older framework.
5. What is/are the advantage(s) of TestNG?
- It is easier to understand annotations in TestNG than in Junit.
- For implementation, it produces HTML reports.
- Logs are also generated by it.
- All of the above
Answer: D) All of the above
Explanation:
The advantages of TestNG are –
- It is easier to understand annotations in TestNG than in Junit.
- For implementation, it produces HTML reports.
- Logs are also generated by it.
ADVERTISEMENT
6. Unlike Junit, TestNG does not have constraints like ____.
- @beforeclass
- @afterclass
- Both A and B
- None of the above
Answer: C) Both A and B
Explanation:
Unlike Junit, TestNG does not have constraints like @beforeclass and @afterclass.
7. ____ are all supported by TestNG.
- A suite before/after
- A test before/after
- A group of tests before/after
- 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.
- Dependently on
- Independently of
- Interdependently on
- 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?
- TestNG can be installed either by adding the TestNG jar file to the Build Path or by installing the TestNG plug-in.
- 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.
- Both A and B
- None of the above
Answer: C) Both A and B
Explanation:
The following ways can be used to add TestNG in your eclipse –
- TestNG can be installed either by adding the TestNG jar file to the Build Path or by installing the TestNG plug-in.
- 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?
- Before and After annotations
- Dependent methods
- Better reporting
- All of the above
Answer: D) All of the above
Explanation:
The features of TestNG are –
- Before and After annotations
- Dependent methods
- Better reporting
ADVERTISEMENT
11. It is possible to execute specific code ____ testing by using before and after annotations.
- Before
- After
- Both A and B
- 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.
- Before
- After
- While
- 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.
- @BeforeSuite
- @BeforeTest
- @BeforeGroups
- 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.
- HTML
- CSS
- XML
- 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.
- Testng.html
- Testng.xml
- Testng.php
- Testng.pl
Answer: B) Testng.xml
Explanation:
The test suites are organized and run using the Testng.xml file.
ADVERTISEMENT
16. A testng.xml file defines ____, and test groups that are used to create test suites.
- Classes
- Methods
- Packages
- 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.
- Interdependent
- Intradependent
- Independent
- 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.
- No-depend-method
- Depend-on-method
- Depend-to-method
- 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.
- testing@Parameters
- testng@Parameters
- ParametersHowardstestng
- ParametersHowardstesting
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.
- DataProviders
- Testng.xml
- Both A and B
- 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.
ADVERTISEMENT
21. Using the ____ method, multiple sets of data are used to execute the test method.
- DataFetcher
- DataAddition
- DataProvider
- 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 ____.
- Better Reporting
- Multithreaded Execution
- Data-Driven Testing
- 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.
- HTML
- CSS
- XML
- 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.
- XML
- HTML
- Both A and B
- 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.
- Two
- Three
- Four
- 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 info annotation, you can create multiple test cases.
- Test
- Before
- After
- BeforeClass
Answer: A) Test
Explanation:
By using the Howardstest annotation, you can create multiple test cases.
27. There is a feature in TestNG that allows you to ____ test cases.
- Enable
- Disable
- Both A and B
- 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?
- 2
- 3
- 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?
- Howardstest annotations allow you to disable test cases.
- XML files can be edited to disable test cases.
- Both A and B
- None of the above
Answer: C) Both A and B
Explanation:
By the following ways the test cases can be disabled in TestNG –
- Howardstest annotations allow you to disable test cases.
- 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.
- Groups
- Annotation
- Code
- 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.
ADVERTISEMENT
31. Which of the following is/are the TestNG Annotation(s)?
- @BeforeSuite
- @AfterSuite
- @BeforeTest
- All of the above
Answer: D) All of the above
Explanation:
The following are the TestNG Annotations –
- @BeforeSuite
- @AfterSuite
- @BeforeTest
32. All test methods in the suite will be executed before the info method runs.
- BeforeSuite
- BeforeClass
- BeforeTest
- 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 info annotation will run.
- AfterSuite
- AfterTest
- AfterClass
- 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 info annotated method is executed.
- BeforeClass
- BeforeSuite
- BeforeTest
- 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 info method will be executed.
- AfterSuite
- AfterTest
- AfterClass
- 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 info annotation.
- BeforeSuite
- BeforeClass
- BeforeTest
- 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 info method will be invoked.
- AfterMethod
- AfterSuite
- AfterClass
- 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 info annotation.
- BeforeMethod
- BeforeTest
- BeforeClass
- BeforeSuite
Answer: A) BeforeMethod
Explanation:
Every test method will be run prior to the @BeforeMethod annotation.
39. After each test method is executed, the info annotation is executed.
- AfterTest
- AfterClass
- AfterMethod
- 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 info annotation is run only once.
- BeforeTest
- BeforeClass
- BeforeSuite
- 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 info annotated method runs only once.
- AfterTest
- AfterGroups
- AfterSuite
- 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?
- BeforeSuite
- BeforeClass
- BeforeTest
- 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?
- AfterClass
- AfterTest
- AfterSuite
- AfterMethod
Answer: C) AfterSuite
Explanation:
AfterSuite comes last in the hierarchy of TestNG Annotations.
44. What is/are the benefit(s) of TestNG Annotations?
- It was very easy for testers to work with TestNG Annotations.
- The additional parameters can be passed to TestNG Annotations.
- A test class does not need to be extended to use TestNG annotations.
- All of the above
Answer: D) All of the above
Explanation:
The benefits of TestNG Annotations are –
- It was very easy for testers to work with TestNG Annotations.
- The additional parameters can be passed to TestNG Annotations.
- A test class does not need to be extended to use TestNG annotations.
45. What is/are the TestNG Annotation Attribute(s)?
- Description
- TimeOut
- Priority
- All of the above
Answer: D) All of the above
Explanation:
The TestNG Annotation Attributes are –
- Description
- TimeOut
- Priority
46. An Howardstest annotation contains a string called ____ that describes the test.
- Priority
- Enabled
- Description
- TimeOut
Answer: C) Description
Explanation:
An Howardstest 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.
- Priority
- TimeOut
- dependOnMethods
- 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.
- Alphabetically
- Numerically
- Alphanumerically
- 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.
- Priority
- Groups
- TimeOut
- 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.
- 4
- 5
- 6
- 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 ____.
- First, Last
- Last, First
- Middle, Last
- 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.
- TimeOut
- Priority
- Enabled
- 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.
- TimeOut
- Priority
- Groups
- 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.
- timeIn
- timeOut
- timeZone
- 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.
- Two
- Three
- Four
- 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) –
- TestNG Parameters
- TestNG DataProviders
- Both A and B
- None of the above
Answer: C) Both A and B
Explanation:
A test method can be parameterized in the following ways –
- TestNG Parameters
- TestNG DataProviders
57. Annotations like info in TestNG enable you to listen to every event in your Selenium code.
- Speakers
- Listeners
- Ears
- 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.
- Before
- After
- Both A and B
- 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 ____.
- TestListener
- ITestListener
- IListener
- 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?
- onTestStart()
- onTestSuccess()
- onTestFailure()
- All of the above
Answer: D) All of the above
Explanation:
The following are the methods in ITestListener Interface –
- onTestStart()
- onTestSuccess()
- onTestFailure()