Top 20 TestNG Framework Interview Questions with Answers

TestNG is a progressive test automation framework which is designed to serve the needs of both software developers and the test engineers. In this post, we’ve selected 20 best interview questions on Selenium TestNG framework to boost your Selenium test automation skills.

But before you begin reading the interview questions, let us tell you a few facts about this framework which you might not know about.

It has some incredible features like built-in annotations and a handful of assertions to test a variety of conditions.

Apart from these turnkey features, the focal point of all of its settings is an XML file. With it, you can control everything beginning from test execution to reporting. You can specify which test to execute and what to exclude, can set the execution order and even prioritize them.

So first of all, just go through a quick overview of the TestNG framework.

TestNG framework overview.

What is TestNG framework and why is it used?

TestNG is actually an advancement over the JUnit framework which is frequently used by Java developers for unit testing of their source code. But there were certain limitations in JUnit framework that led to the rise of TestNG framework.

TestNG framework interview questions

TestNG Framework Interview Questions.

TestNG source code is controlled by the Apache software license and it is freely available for the download. The most common use of TestNG framework is with the Selenium WebDriver to produce browser based test automation.

TestNG framework supports intuitive HTML report style to share with stakeholders. The report includes product health indicators such as pass/fail count, the age of defect etc. This TestNG report fills the gap cropped up by the inability of WebDriver to generate the report. On the top, TestNG offers exceptional handling support that allows a program to run without exiting abruptly.

What are the essential TestNG framework features?

TestNG framework introduces some new features that make it more powerful and easier to use, such as:
1- Annotations: An annotation is a form of metadata in java which can be applied to various elements of java source code so that any tool, debugger or application program can use these annotations. Classes, methods, variables, parameters and packages may be annotated. For your information, please note that the annotations in java source code are compiled into byte-code with other class members. And programmers can use reflection to query this metadata information to decide the appropriate action to perform in any particular context.

A metadata is data about data. Metadata adds some additional flags on your actual data. So that in runtime JVM can identify these flags and use this metadata information to take appropriate action.

2- Provides arbitrarily big thread pools to run tests in their own thread, one thread per test class, etc.
3- Ensure that your code is thread-safe.
4- Flexible test configuration.
5- Supports data-driven testing (with @DataProvider).
6- Support for parameters.
7- Powerful execution model (Independent of TestSuite).
8- Easy integration with a variety of tools and plug-ins (Eclipse, Maven, Jenkins etc.).
9- Embeds Bean Shell for further flexibility.
10- Uses default JDK functions for runtime and logging (no dependencies).
11- Dependent methods for application server testing.

Suggested Readings.

Till now you would have gained a fair idea about the TestNG framework and its features. However, there is plenty of nice material available on our blog which you can refer to enhance your skills.

If you are a learner then you would also like reading our lately published posts on Selenium WebDriver interview questions and will love to attempt a brain shaking quiz.

4. Selenium Quiz to Boost Your Test Automation Skills.

Now, it’s time to loop through the set of top Selenium TestNG interview questions that we’ve rolled up after in-depth research.

Top 20 TestNG Framework Interview Questions & Answers.

Question #1) What is the significance of <testng.xml> file?

Answer: In a Selenium TestNG project, we use <testng.xml> file to configure the complete test suite into a single file. This file makes it easy to group all the test suites and their parameters in one file. It also gives the ability to pull out subsets of your tests or split several runtime configurations. Few of the tasks which we can group in the <testng.xml> file are as follows.

1- Can configure test suite comprising of multiple test cases to run from a single place.
2- Can include or exclude test methods test execution.
3- Can mark a group to include or exclude.
4- Can pass parameters in test cases.
5- Can add group dependencies.
6- Can configure parallel test execution.
7- Can add listeners.


Question #2) How to pass parameter through <testng.xml> file to a test case?

Answer: You can set the parameter using the below syntax in the <testng.xml> file.

<parameter name="browser" value="FFX" />

Here, name attribute represents the parameter name and value signifies the value of that parameter. Then we can use that parameter in the selenium WebDriver software automation test case using the bellow syntax.

@Parameters ({"browser"})


Question #3) How to exclude a @Test method from a test case with two @Test methods? Is it possible?

Answer: Yes, you need to add @Test method in the exclude tag of <testng.xml> file as mentioned below.

<!DOCTYPE suite SYSTEM "" >
<suite name="Test Exclusion Suite">
  <test name="Exclusion Test" >
      <class name="Your Test Class Name">
       <exclude name="Your Test Method Name To Exclude"/>


Question #4) How to skip a @Test method from execution?

Answer: You can use the below syntax inside @Test method to skip a test case from test execution.

throw new SkipException("Test Check_Checkbox Is Skipped");

It will throw skip exception and @Test method will be ignored immediately from execution.


Question #5) Can you arrange the below <testng.xml> tags from parent to child?


Answer: The <testng.xml> file will have the following structure.

  • The parent tag in the <testng.xml> file is the <suite> tag.
  • <suite> tag can include one or more <test> tags.
  • <test> tag can include the <classes> tag.
  • <classes> tag can include one or more <class> tags.
  • <class> tag wraps the <methods> tag where we define the test methods to include or exclude.

Hence, the correct order of the TestNG tags would be.



Question #6) How to define the priority of @Test method? Also, mention its usage?


In your Selenium WebDriver project, you can set priority for TestNG @Test annotated methods as shown in the following example.


Using priority, you can manage @Test method execution sequence as per your requirement. That means @Test method with priority = 0 will run 1st and @Test method with priority = 1 will execute 2nd and so on.


Question #7) Can you specify any 6 assertions of TestNG to be used in a Selenium WebDriver software testing tool.

Answer: There are multiple assertions available In TestNG but generally we use the following assertions in out test cases.

1- assertEquals
2- assertNotEquals
3- assertTrue
4- assertFalse
5- assertNull
6- assertNotNull


Question #8) Why soft assertion is used in Selenium WebDriver and TestNG automation project?

Answer: TestNG soft assertion allows to continue the test execution even if the assertion is failed. That means once the soft assertion fails, remaining part of the <@Test> method is executed and the assertion failure is reported at the end of the <@Test> method.


Question #9) How to apply regular expression in <testng.xml> file to find @Test methods containing “product” keyword?


Refer below example, here we’ve used a regular expression to find @Test methods containing keyword “product”.

     <include name=".*product.*"/>


Question #10) What are the time unit we specify in test cases and test suites? minutes? seconds? milliseconds? or hours? Give Example.

Answer: Time unit we specify at @Test method level and test suite level which normally set in milliseconds unit.


Question #11) List out the benefits of TestNG over Junit?


TestNG framework has following benefits over JUnit.

1- TestNG annotations are more logical and easier to understand.

2- Unlike JUnit, TestNG does not require to declare @BeforeClass and @AfterClass.

3- There is no method name constraint in Selenium TestNG framework.

4- TestNG supports three additional setups:

4.1- @Before/AfterSuite,

4.2- @Before/AfterTest, and

4.3- @Before/AfterGroup.

5- In Selenium TestNG projects, there is no need to extend any class.

7- In TestNG, it is possible to run Selenium test cases in parallel.

8- TestNG supports grouping of test cases which is not possible in JUnit.

9- Based on the group, TestNG allows you to execute the test cases.

10- TestNG permits you to determine the dependent test cases. Every test case is autonomous to other test cases.


Question #12) What are the basic steps for drafting TestNG test cases?


Following are the most common steps for writing TestNG test cases.

1- Write down the business logic of your test.

2- Add appropriate TestNG annotations in your code.

3- In <build.xml> or <testing.xml>, add the information about your test.

4- Run your TestNG project.


Question #13) List out different ways to run TestNG?


You can run TestNG in the following ways.

1- Start directly from the Eclipse IDE, or

2- Run using the IntelliJ’s IDEA IDE.

3- Run with ant build tool.

4- Launch from the command line.


Question #14) In TestNG how can you disable a test?


To disable the test case, you can use the following annotation.

  • @Test(enabled = false).


Question #15) Explain what does the test timeout mean in TestNG?

Answer: The timeout test in TestNG is nothing but the time allotted to perform unit testing. If the unit test fails to finish in that specific time limit, TestNG will abandon further testing and mark it as a failed.


Question #16) What is exception test and why is it used for?


TestNG provides an option for tracing the Exception handling of code. You can verify whether a code throws the desired exception or not. The expectedExceptions parameter is availed along with @Test annotation. Please refer the below example for clarity.

package com.techbeamers.testng.examples.exception;

import org.testng.annotations.Test;

public class TestRuntime {

@Test(expectedExceptions = { IOException.class })

 public void exceptionTestOne() throws Exception {

 throw new IOException();


 @Test(expectedExceptions = { IOException.class, NullPointerException.class })

 public void exceptionTestTwo() throws Exception {

 throw new Exception();




Question #17) Explain what is parametric testing?


Parameterized testing lets the programmer re-run the same test with different values. TestNG allows you to pass parameters directly to the test methods using the two ways as given below.

1- With testing.xml.

2- With Data Providers.


Question #18) Explain what does @Test(invocationCount=?) and (threadPoolSize=?) indicates?


1- @Test (threadPoolSize=?): The threadPoolSize attribute directs TestNG to create a thread pool to run the test method through multiple threads. With thread pool, the running time of the test method reduces considerably.

2- @Test(invocationCount=?): The invocation count refers to the no. of times TestNG should run the test method.


Question #19) What are the different ways to produce reports for TestNG results?


TestNG offers following two ways to produce a report.

Listeners: For a listener class, the class has to implement the org.testng./TestListener interface. TestNG notifies these classes at runtime when the test enters into any of the below states.
e.g. Test begins, finishes, skips, passes or fails.

Reporters: For a reporting class to implement, the class has to implement an org.testng/Reporter interface. When the whole suite run ends, these classes are called. When called, the object consisting the information of the whole test run is delivered to this class.


Question #20) How does TestNG allow you to state dependencies?


TestNG supports two ways to declare the dependencies.

1- Using attributes dependsOnMethods in @Test annotations.

2- Using attributes dependsOnGroups in @Test annotations.

Summary – TestNG Framework Interview Questions and Answers.

We hope, with the above list of questions, you would gain enough knowledge and confidence to get a breakthrough in your next interviews. And that’s what we want to achieve by helping the aspiring software programmers and test engineers through our blog.

In this endeavor, you can also lend your support to us by leaving your valuable feedback.

In the end, we suggest if you like the post, then please share this in your friend circle and the social media of your choice.


All the Best,



  1. Sunil
    • Harsh S.
  2. Vaishali
    • Meenakshi Agarwal
  3. sandhya
    • Meenakshi Agarwal