Thursday, 13 June 2019

Frequently asking TestNG Interview Questions

Selenium Interview Questions             Maven Interview Questions

Appium Interview Questions             API Automation Testing Interview Questions


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?
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)
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>
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:
1
@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>
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.
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.
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.
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, invocationCount = 20)
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.
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

================================================================================
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?


Selenium Interview Questions             Maven Interview Questions


Appium Interview Questions             API Automation Testing Interview Questions

No comments:

Post a Comment