Top 50+ TestNG Interview Questions Asked in Interview

When we have certain professional skill sets then we want to utilize them in the right place. Generally, we are very choosy in terms to get the right job. Hence, we need to crack various rounds of interviews to get into our favorite jobs or best position in our current workplace. If you are a test automation engineer, then you must be aware of the TestNG. It is very expected that interviewer asks a lot more questions on TestNG, so we have compiled a great list of TestNG interview questions which will definitely help you crack the interview to get the right job for you.

These TestNG interview questions are compiled after interactions with different interviewers and the experience shared by candidates. Some of the questions are also from my previous interviews given by me, therefore, these are the best TestNG interview questions to help you overcome the fear of failure.

It is highly recommended that you must go through these TestNG interview questions before you appear for the interview. These questions are categorized into three levels namely- Beginner, Youth and Legend levels.

Suggested Interview Questions: Top 200 Selenium Interview Questions

List of Best TestNG Interview Questions

Let’s start the Interview…. OOPS! Let’s start looking into the best TestNG interview questions.

TestNG Interview Questions by Avinash Mishra

TestNG Interview Questions Level- Beginner

Question# 1: Can you tell me which unit test framework do you use?

Answer: TestNG

Question# 2: What is TestNG?

Answer: TestNG is a testing framework which is used to make testing activities simpler, effective, convenient and disciplined.

Question# 3: What does NG mean in TestNG?

Answer: NG stands for ‘Next Generation’. It is the next generation of framework after Junit.

Question# 4: What are the testing processes are testable with TestNG?

Answer: We use TestNG for the broad range of testing processes from Unit testing to Integration testing.

Question# 5: What are the importance of using TestNG in our automation project?

Answer: We use TestNG for the following benefits:

  • We define different test activities within annotations
  • It supports parallel execution of the test cases
  • TestNG supports default threading in parallel execution
  • We define dependencies of one test methods/groups over another
  • TestNG effectively helps to define test groups
  • It supports priority assignment to the Tests
  • Parameterizations are easily implemented using @Parameters annotation in TestNG
  • Data-driven testing is efficiently implemented using @DataProvider annotation in TestNG
  • Different types of Assertion commands are available to validate the scenarios
  • We can even run TestNG based Selenium projects from the command prompt
  • It gives a detailed test report
  • TestNG supports retry of failed test cases multiple times
  • We can easily implement listeners through ITestListener
  • TestNG separately creates an XML file for failed test scenarios

Question# 6: What are different annotations available in TestNG?

Answer: Click here to know details about annotations in TestNG.

Question# 7: How do we run tests created through TestNG?

Answer: We trigger tests through the testng.xml file.

Question# 8: What are the significances of the testng.xml file?

Answer: Followings are the significances of testng.xml file:

  • All the tests are triggered by testng.xml file
  • It supports inclusion and exclusion of the tests
  • Parameters are passed from testng.xml file
  • It supports the addition of dependency of groups
  • Parallel execution and thread counts are defined in the testng.xml file
  • XML creates child XML file for failed tests as testng-failed.xml

Question# 9: Can we run TestNG Selenium project from the command prompt?

Answer: Yes.

Question# 10: What are assertions in TestNG?

Answer: TestNG supports various Assert commands to validate the expected and actual conditions of the scenarios. Some of the Assert commands in TestNG are as follows:

  • assertEquals(String actual, String expected)
  • assertNotEquals(String actual, String expected)

Click here to read more…

TestNG Interview Questions Level- Youth

Question# 11: How do we send parameters from a testng.xml file?

Answer: testng.xml support parameterization for @Parameters annotation so we send values from testng.xml by defining below statement:

<parameter name=”name of the parameter” value=”value of the parameter”>

Click here to read more…

Question# 12: Can we handle expected exceptions with TestNG?

Answer: Yes.

Question# 13: How do we handle expected exception with TestNG?

Answer: We use the following statement to handle expected exception with TestNG:

@Test(expectedExceptions=ArrayIndexOutOfBoundsException.class)

Question# 14: How do we set the execution priority of the tests?

Answer: We use priority keyword along with @Test annotation to set the priority of the test. Below statement sets the priority of the test:

@Test(priority=0)

public void test1(){

}



@Test(priority=1)

public void test2(){

}

Question# 15: What are different techniques to implement parameterization in the Selenium project with TestNG?

Answer: We achieve parameterization in Selenium with TestNG by following techniques:

Question# 16: How do we combine tests with same group identifications?

Answer: We use groups keyword to combine tests of the same group. Here is the implementation:

@Test (groups = {“groupName1”,  “groupName2”})

Question# 17: How to include and exclude groups from testng.xml?

Answer:

<groups>
<run>
<exclude name=”group1”>
<include name=”group2”>
</include>
</exclude>
</run>
</groups>

Click here to know more…

Question# 18: How are tests run in parallel in TestNG?

Answer: We use “parallel” keyword to run tests in parallel.

Question# 19: How to starts different threads in parallel in TestNG?

Answer: We give integer value to the keyword “thread-count” in the testng.xml file to start multiple threads in parallel.

Question# 20: What are parallel attributes in TestNG?

Answer: Parallel keyword has following attributes to trigger tests in parallel:

  • tests
  • classes
  • methods
  • instances
  • true
  • false

Question# 21: How to skip tests at runtime with TestNG?

Answer: We throw SkipExceotion(String message) to skip tests at runtime.

Click here to know more…

Question# 22: Can we ignore some tests with TestNG?

Answer: Yes.

Question# 23: How to ignore tests with TestNG?

Answer: We use the following statement with the @Test annotation to ignore tests with TestNG.

@Test(enabled=false)

Question# 24: How to define dependencies with TestNG?

Answer: We use the dependsOnMethods keyword to define dependencies with TestNG.

Click here to read in detail…

TestNG Interview Questions Inviul

TestNG Interview Questions Level- Legend

Question# 25: How to design a data-driven framework using TestNG?

Answer: We use @DataProvider annotation to design data-driven framework in Selenium with TestNG.

Click on below link to know more.

How to create a data-driven framework with TestNG?

Question# 26: What is the return type of method within @DataProvider annotation?

Answer: Method implemented with @DataProvider annotation has 2-D Object as its return type.

Question# 27: How to perform advanced logging in Selenium with TestNG?

Answer: We use Test listeners to implement advanced logging with TestNG.

Question# 28: What are TestNG Listeners?

Answer: TestNG listeners are used for intelligent and advanced reporting and logging in the Selenium project. We implement TestNG listeners by following ways:

  • TestNG listener implementation by- @Listener annotation
  • TestNG listener implementation through the testng.xml file

Question# 29: What is the difference between listener implementation through @Listener annotation and through the testng.xml file?

Answer: TestNG listener implementation through @Listener annotation is restricted to a particular class only, whereas, listener implementation through the testng.xml file is applicable to the entire test suite.

Question# 30: How to implement TestNG listener through the testng.xml file?

Answer: We add following statement in testng.xml file to implement TestNG listener.

<listeners>
<listener class-name=”Class_Name”/>
</listeners>

Question# 31: What are the listeners’ name for logging and reporting in TestNG?

Answer: We implement ITestListener for effective logging and IReporter listeners for custom reporting in TestNG.

Here is the tutorials link for their implementation:

Question# 32: What is the interface name to implement test retry with TestNG?

Answer: We implement IRetryAnalyzer and IAnnotationTransformer interfaces to implement retry of failed tests with TestNG.

Question# 33: How to define a regular expression in the testng.xml file to search tests which contain keyword “regression”?

Answer:

<methods>
                <include name=”.*regression.*”/>
</methods>

Question# 34: What is the time unit to define in test suites?

Answer: milliseconds.

Question# 35: How to run particular test methods multiple times?

Answer: we use the following statement to invoke particular tests for a certain number of times.

@Test(invocationCount = 20)
public void myTest(){

}

Question# 36: How to run a test method from multiple different threads?

Answer: Following code specifies that myTest() method will be invoked from 5 different threads.

@Test (threadPoolSize = 5, <code class=”My Class”>invocationCount = </code><code class=”value”>20</code>)
public void myTest(){

}

Question# 37: How to give timeouts to different threads with TestNG?

Answer: We use ‘timeOut’ keyword to add the time delay. Here is the statement:

@Test (threadPoolSize = 5, invocationCount = 20, timeOut = 20000)
public void myTest(){

}

Question# 38: What is the use of @Factory annotation in TestNG?

Answer: @Factory annotation helps to run different classes from a sing class. It is also used to set the value of the parameterized constructor with the help of @DataProvider annotation.

Click here to read more on @Factory annotation implementation…

Question# 39: What is the return type of method written within @Factory annotation?

Answer: The return type of the method written within @Factory annotation is 1D Object array.

Question# 40: What is the command to run TestNG using command prompt?

Answer:

set classpath=pathOfBinFolder/bin; pathOfLibFolder/lib/*;
java org.testng.TestNG pathOftestng.xml/testng.xml

TestNG Interview Questions Level- Miscellaneous

Here are some of the miscellaneous TestNG interview questions which are generally not asked in an interview, but you should have knowledge of it.

Question# 41: Which version of TestNG have you used in your previous project?

Question# 41: How did you install TestNG in your IDE?

Question# 42: Which IDE did you use for TestNG?

Question# 43: Have you extended your existing testng.xml file with another testng.xml file?

Question# 44: When did TestNG come in picture?

Question# 45: Who developed TestNG?

Question# 46: How is TestNG better than Junit?

Question# 47: What is the folder name generated after the first test run through the testng.xml file?

Question# 48: What is emailable-report in TestNG?

Question# 49: Can we pass a large set of parameters through @Parameters annotation?

Question# 50: How to perform inheritance in the testng.xml file?

These are all about TestNG Interview Questions. You may join our Facebook group for more updates on Selenium and TestNG. Click below link to know more about TestNG.

 

Join Inviul fb group

Leave a Reply