TestNG Interview Questions

TestNG Interview Questions

TestNG Interview Questions

TesNG is widely used testing framework as compared to Junit. so it is obvious that you will come through TestNG interview questions below most commonly asked interview questions. Actually TesNG   is a unit testing Framework for Java.

1. What is TestNG?

TestNG is a testing framework inspired from JUnit and NUnit but introducing some new functionalities that make it more powerful and easier to use, such as:

  • Run your tests in arbitrarily big thread pools with various policies available (all methods in their own thread, one thread per test class, etc)
  • Supported by a variety of tools and plug-ins (Eclipse, IDEA, Maven, etc…).
  • Embeds BeanShell for further flexibility.
  • Test that your code is multithread safe and Flexible test configuration.
  • Default JDK functions for runtime and logging (no dependencies).
  • Dependent methods for application server testing.

2. What are the advantages of TestNG?

  • TestNG provides parallel execution of test methods.
  • It allows to define dependency of test cases
  • TestNG has a parameter annotation that allows values to pass as arguments to test scripts.
  • Different Annotations are supported.
  • It allows data driven testing using @DataProvider annotation.
  • It has different assertions which is use for comparing the expected and actual results.

3. What are the annotations available in TestNG?


4. What is the correct order of TestNG tags inside testng.xml from parent to child?

  • <suite>
  • <test>
  • <classes>
  • <class>
  • <methods>
5.How To Pass Parameter Through Testng.xml File To a Test Case ?

<suite name="Parameterization Test Suite">
<test name="Testing Parameterization">
<parameter name="browser" value="Firefox"/> 
<class name="com.parameterization.TestParameters" />

//Test Script

public class TestScript { @Test @Parameters("browser") public void Testcase(String browser){ if(browser.equals("firefox")){ System.out.println("Open Firefox Driver"); } else if(browser.equals("chrome")){ System.out.println("Open Chrome Driver");} } }


6.What Are The Core Features Of TestNG Framework?

  • Concurrency – TestNG is use to run the test cases in parallel and it creates a thread for each test and execute it in thread safe manner.
  • Dependency – we can write a test method which depends on a single or a group of test methods. This feature ensures the execution of the dependency methods before the actual test.
  • Prioritization – We can priorities the test cases in TestNG with help of priority keyword used inside @Test Annotation .
  • Grouping – It is a unique feature of TestNG which was not present in the JUnit framework. We can group test case with help of Group keyword used inside @Test Annotation.
  • Parameterization – TestNG has a parameter annotation that allows values to pass as arguments to test methods.
  • Data Sourcing – TestNG introduces data provider annotation to take input from external sources like excel.

7. How will you do data driven testing in TestNG?

We can do data driven testing in TestNG with help below methods.
• With testing.xml
• With Data Providers

In TestNG.xml we can pass test data to a test script with help of Parameter tag in Testng and also data provider is used to store data taken from Excel sheet and use it in our scripts

8. Explain what does @Test(invocationCount=_) and (threadPoolSize=_ ) indicates ?

  • @Test (threadPoolSize=_): The threadPoolSize attributes is used to tell TestNG to form a thread pool to run the test method through multiple threads. By using threadpool, we can reduce the execution time of Test methods.
  • @Test(invocationCount=_): The invocationcount is use to repeat the same sets of test methods for the given number of times.

9.In TestNG how can you disable a test?

  • To disable the test case in TestNG we just need to use the below annotation.


10. What are some common assertions provided by testNG?

 Some of the common assertions provided by testNG are-

  • assertEquals(String actual, String expected, String message) 
  •  assertNotEquals(double data1, double data2, String message) 
  • assertFalse(boolean condition, String message)
  • assertTrue(boolean condition, String message)
  • assertNotNull(Object object)
  • fail(boolean condition, String message)
  • true(String message)

11.What Is The Purpose Of The “TestNG.XML” File?

The “TestNG.XML” is a configuration file which contains the project settings. We can change the execution test , classes and methods with help of TestNG.xml 

We can do several execution configurations with help of this TestNG.xml. The list is as follows.

  • Setup multiple tests to run with a single click.
  • Include/Exclude test cases.
  • Select a specific group or groups.
  • Supply parameters for tests.
  • Introduce group-level dependencies.
  • Setup test parallel test execution.
  • Configure listeners for tests.

These are the top most TestNG interview questions asked please read them before going to interview. and there very simple and easy to understand and if you found any difficulty just let me know in the comment section below

TestNG Annotations is also very frequently asked question into the interview room. so I will suggest you to read this blog also.

Did we left something?

Comment down below and share your knowledge with others too , Thanks.

Or Please give your valuable feedback to us...


Author: Saad Mansuri

Leave a Reply

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